Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $name;
- $price;
- $choice;
- $cart = array();
- do {
- echo "1. Add an item to your cart.\n";
- echo "2. Remove an item from your cart.\n";
- echo "3. Get the total balance of your cart.\n";
- echo "4. Total number of items in your cart.\n";
- echo "5. Check your cart for specific item.\n";
- echo "6. Check your cart for count of specific item.\n";
- echo "7: See everything in the cart.\n";
- echo "\n0. Exit!\n";
- echo "\nPlease enter a number between 0 and 7 : ";
- $choice = trim(fgets(STDIN));
- //} while(!(($choice == "0") || ($choice == "1") || ($choice == "2") || ($choice == "3") || ($choice == "4") || ($choice == "5") || ($choice == "6") || ($choice == "7")));
- switch ($choice) {
- case 1:
- add();
- break;
- case 2:
- remove();
- break;
- case 3:
- balance();
- break;
- case 4:
- totalitems();
- break;
- case 5:
- itemexist();
- break;
- case 6:
- numberofeach();
- break;
- case 7:
- showall();
- break;
- case 0;
- default:
- echo "Thank you for using the shopping cart";
- }
- }while ($choice != 0);
- function add(){
- echo "What would you like to add to your shopping cart?";
- $handle_name = fopen("php://stdin","r");
- $name = fgets($handle_name);
- echo "How much does it cost?";
- $handle_price = fopen("php://stdin","r");
- $price = fgets($handle_price);
- $cart['item'][] = array("name"=>$name,"price"=>$price);
- print_r($cart);
- }
Add Comment
Please, Sign In to add comment