Skip to content

Instantly share code, notes, and snippets.

@manifoldhiker
Created April 18, 2017 12:42
Show Gist options
  • Save manifoldhiker/3de03152d3dc48279f0c129b07e949a7 to your computer and use it in GitHub Desktop.
Save manifoldhiker/3de03152d3dc48279f0c129b07e949a7 to your computer and use it in GitHub Desktop.
<?php
class Product{
public $name ;
public $price ;
public $allowedAge ;
public function __construct($name, $price, $allowedAge)
{
$this->name = $name;
$this->price = $price;
$this->allowedAge = $allowedAge;
}
}
$PRODUCTS = array(
new Product('Grechka', 125, 16),
new Product('Pizza', 250, 18),
new Product('Yabloko', 50, 10),
new Product('jQuery', 100500, 65),
);
function getBill(){
}
function profileSettings(){
}
function finish(){
}
function startShopping(){
global $PRODUCTS ;
echo "Shopping..\n" ;
pick_product:
foreach($PRODUCTS as $n=>$product){
echo $n+1 . " --- $product->name costs $product->price gryvens, allowed from $product->allowedAge years. \n" ;
}
$choise = readline("Your choise: ") - 1;
if(_containsKey($PRODUCTS,$choise)){
echo "Oh yeah!";
} else {
echo "Incorrect input, young man! Try again..";
goto pick_product;
}
}
function _containsKey($arr, $k){
foreach($arr as $key=>$value){
if($key == $k){
return true ;
}
}
return false ;
}
echo "Консольное приложение \"неоригинальный магазин.\n";
echo "1. Начать покупки - “1”\n";
echo "2. Получить итоговый счет - “2”\n";
echo "3. Настройки профиля - “3”\n";
echo "4. Выход из программы - “0”\n";
start:
$choise = readline("Ваш выбор: ");
switch ($choise) {
case "1" :
startShopping();
break ;
case "2" :
getBill() ;
break ;
case "3" :
profileSettings() ;
break ;
case "0":
finish();
break;
default :
echo "Неправильный ввод! Попробуйте еще раз!\n";
goto start ;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment