title: Getting Data From Multi-level Array
body: <p>Question below.</p>
  
  <p>This is the solution I came up with based on Pixeler's answer.</p>
  
  <pre><code>&lt;?php
  $i = 0;
  foreach ($array as $k1 =&gt; $v1) {
          if (is_array($v1)) {
              echo $k1."&lt;br /&gt;";
                  foreach ($v1 as $k2 =&gt; $v2) {
                      echo "--".$k2."&lt;br /&gt;----".$v2."&lt;br /&gt;";
                  }
              $i++;
          }
          echo "&lt;br /&lt;br /&gt;";
  }
  ?&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;?php
  $array = array( "Apples" =&gt; array("Red" =&gt; "$2.95", "Green" =&gt; "$2.45"),
                  "Oranges" =&gt; array("Navel" =&gt; "$4.95"),
                  "Grapes" =&gt; array("Purple" =&gt; "$3.75", "Green" =&gt; "$3.25")
                );
  ?&gt;
  </code></pre>
  
  <p>Is it possible to take what's above and get the text for each value by calling a number?
  How could I do something like this?...</p>
  
  <pre><code>&lt;?php
  echo $array[0];
  //Outputs "Apples"
  
  echo $array[0][0];
  //Outputs "Red"
  
  echo $array[0][0][0];
  //Outputs "$2.95"
  
  echo $array[3][2][1];
  //Outputs "$3.25" (Grapes &gt; Green &gt; Price)
  ?&gt;
  </code></pre>
  
  <p><strong>EDIT:</strong> The idea is that I can return the first level (Apples, Oranges, Grapes), second level (Red, Green, Navel, Purple, Green), and third level ($2.95, $2.45, $4.95, $3.75, $3.25) by calling a number.</p>
  
  <p>For example, I want to do something like this:</p>
  
  <pre><code>&lt;?php
  
  count($array); //returns 3 (Apples, Oranges, Grapes)
  
  //Do some for/foreach function that will produce the following:
  
  //Apples
  //-&gt;Red: $2.95
  //-&gt;Green: $2.45
  //Oranges
  //-&gt;Navel: $4.95
  //Grapes
  //Purple: $3.75
  //Green: $3.25
  
  //I'm hoping to structure the code like this:
  
  foreach($i = 0; $i =&lt; count($array); $i++){
      //echo title of array (Apples)
      //echo each child key and it's value (Red: $2.95; Green: $2.45)
  
      foreach($secondcounter = 0; $secondcounter =&lt; count($array[$i]); $secondcounter++){
          echo array_key($array[$i][$secondcounter]) . ": " .$array[$i][$secondcounter];
          //Note: I don't actually know if array_key does the trick or not, it's meant to return "Red" in this case, while the non array_key()'d is meant to return the price of red apples, $2.95
  }
  
  ?&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT:</strong> It is important to note that I cannot use words to call the data. I must use numbers, i.e. [0] to call the first item in the array, because Apples could change depending on what row of data I load from my database. In other words... Apples could actually turn out to be Books, and Red could turn out to be the name of the book => price.</p>
  
  <p>I'm intending on using serialize/unserialize to store and retrieve the data from the database, although I'm not overly familiar with these functions, I had a brief look at them and they seem reasonably easy to use.</p>
  
  <hr>
  
  <p>I've been researching for hours but I cant find anything.
  It is vital that I am able to call the data by numbers, not text. So $array["Apples"] is unacceptable.</p>
  
  <p>I have also looked at json_decode and serialize/unserialize, and I think I get the basic idea of them from a brief look... but I think my main issue is understanding how to call the above data as presented in my example. Any help would be really great.</p>