daily pastebin goal
47%
SHARE
TWEET

Untitled

a guest Apr 27th, 2018 41 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $name;
  3. $price;
  4. $choice;
  5. $cart = array();
  6. do {
  7. echo "1. Add an item to your cart.\n";
  8. echo "2. Remove an item from your cart.\n";
  9. echo "3. Get the total balance of your cart.\n";
  10. echo "4. Total number of items in your cart.\n";
  11. echo "5. Check your cart for specific item.\n";
  12. echo "6. Check your cart for count of specific item.\n";
  13. echo "7: See everything in the cart.\n";
  14. echo "\n0. Exit!\n";
  15. echo "\nPlease enter a number between 0 and 7 : ";
  16. $choice = trim(fgets(STDIN));
  17. //} while(!(($choice == "0") || ($choice == "1") || ($choice == "2") || ($choice == "3") || ($choice == "4") || ($choice == "5") || ($choice == "6") || ($choice == "7")));
  18.  
  19. switch ($choice) {
  20.     case 1:
  21.         add();
  22.         break;
  23.     case 2:
  24.         remove();
  25.         break;
  26.     case 3:
  27.         balance();
  28.         break;
  29.     case 4:
  30.         totalitems();
  31.         break;
  32.     case 5:
  33.         itemexist();
  34.         break;
  35.     case 6:
  36.         numberofeach();
  37.         break;
  38.     case 7:
  39.         showall();
  40.         break;
  41.     case 0;
  42.     default:
  43.         echo "Thank you for using the shopping cart";
  44. }
  45. }while ($choice != 0);
  46. function add(){
  47.         echo "What would you like to add to your shopping cart?";
  48.         $handle_name = fopen("php://stdin","r");
  49.         $name = fgets($handle_name);
  50.         echo "How much does it cost?";
  51.         $handle_price = fopen("php://stdin","r");
  52.         $price = fgets($handle_price);
  53.         $cart['item'][] = array("name"=>$name,"price"=>$price);
  54.         print_r($cart);
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top