title: How to push an associative array inside an new array
body: <p>Hello I am trying to push associative arrays inside an array. But I can't figure out how to do so. All I managed to do is to push the index without its associated value. Can you guys help me figure this out?</p>
  
  <p>Here's my code :</p>
  
  <pre><code>&lt;?php
  $mainshelf = array(
                 shelf1=&gt; array('apple'=&gt;5, 'banana'=&gt;6, 'lemon'=&gt;7, 'apricot'=&gt;8, 'mango' =&gt;9),
                 shelf2=&gt; array('salad'=&gt;13, 'tomato'=&gt;12, 'carrot'=&gt;2, 'zuchini'=&gt;15, 'potato' =&gt;20),
                 shelf3=&gt; array('veal'=&gt;20, 'mutton'=&gt;22, 'chicken'=&gt;19, 'pork'=&gt;25, 'fish' =&gt;17)
                 );
  
   ?&gt;
  
  &lt;?php
  session_start();
  include 'data.php';
  
  //Generate options in each select
  function select($shelf){
          foreach($shelf as $key=&gt;$value){
              echo "&lt;option&gt;$key&lt;/option&gt;";
          }
      }
  
  
  
  // Creating the shopping cart tab
  if(!isset($_SESSION['cart'])){
      $_SESSION['cart']=[];
  }
  
  //Storing items in shopping cart
  function listitems($selectshelf){
      if(!empty($selectshelf)){
          array_push($_SESSION['cart'],$selectshelf);
      }
  
  }
  
  
  // Print out the cart's content
  function cartcontent() {
      if(!empty($_SESSION['cart']))
          foreach($_SESSION['cart'] as $key=&gt;$value){
              echo "&lt;p&gt;$value&lt;/p&gt;";
          }
  
  }
  
  
     ?&gt;
  
    &lt;!DOCTYPE html&gt;
     &lt;html&gt;
     &lt;head&gt;
  &lt;link rel="stylesheet" type="text/css" href="php.css"&gt;
           &lt;/head&gt;
           &lt;body&gt;
           &lt;div id="container_shelf"&gt;
             &lt;div class="shelf"&gt;
              &lt;h2&gt;Fruits&lt;/h2&gt;
          &lt;form action="php1.php" method="post"&gt;
              &lt;select name="fruits"&gt;Fruits
                  &lt;?php select($mainshelf[shelf1])?&gt;
                  &lt;?php listitems($_POST['fruits'])?&gt;
              &lt;/select&gt;&lt;br&gt;
              &lt;input type="submit" value="Add to cart"&gt;
  
          &lt;/form&gt;
      &lt;/div&gt;
  
      &lt;div class="shelf"&gt;
          &lt;h2&gt;Vegetables&lt;/h2&gt;
          &lt;form action="php1.php" method="post"&gt;
              &lt;select name="vegetables"&gt;Vegetables
                  &lt;?php select($mainshelf[shelf2])?&gt;
                  &lt;?php listitems($_POST['vegetables'])?&gt;
              &lt;/select&gt;&lt;br&gt;
              &lt;input type="submit" value="Add to cart"&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  
      &lt;div class="shelf"&gt;
          &lt;h2&gt;Meat&lt;/h2&gt;
          &lt;form action="php1.php" method="post"&gt;
              &lt;select name="meat"&gt;Meat
                  &lt;?php select($mainshelf[shelf3])?&gt;
                  &lt;?php listitems($_POST['meat'])?&gt;
              &lt;/select&gt;&lt;br&gt;
              &lt;input type="submit" value="Add to cart"&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  
  
  
  
  &lt;/div&gt;
  
  &lt;div id='shopping_cart'&gt;
          &lt;h2&gt;Shopping cart&lt;/h2&gt;
          &lt;?php cartcontent(); echo"&lt;br&gt;"?&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>
  </p>