Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming I understand what you're trying to do, the way you're iterating over the $mmy array isn't correct. By defining it like this:</p> <pre><code>$mmy = array(array("Chevrolet Truck", "C 1500 SERIES", "2005", "V8 5.7L (K)"), array("Nissan Pickup", "D21 PICKUP", "1993", "2.4 L"), array("TOYOTA CAMRY", "LE", "2001", "2.8L V6") ); </code></pre> <p>You're creating an array that contains 3 entries: each an array that contain 4 entries. These are stored at the keys 0-3. So, to iterate over your array like you have it, do this:</p> <pre><code>for ($i = 0; $i &lt; count($mmy); $i++) { $row = $mmy[$i]; echo "&lt;li&gt;&lt;b&gt;The row number $i&lt;/b&gt;"; echo "&lt;ul&gt;"; for ($j = 0; $j &lt; count($row); $j++) { echo "&lt;li&gt;" . $row[$j] . "&lt;/li&gt;"; } echo "&lt;/ul&gt;"; } </code></pre> <p>This will iterate through the outer row, generating a ul tag, then inside of it will generate an li tag for each element in the inner array.</p> <p>You only need one inner loop here. The outer loop will iterate over all of top level entries in $mmy, and the inner loop will iterate over what is inside the inner arrays.</p> <p>A possibly superior solution is to use arrays with user defined keys, like so:</p> <pre><code>$mmy = array( array('make' =&gt; "Chevrolet Truck", 'model' =&gt; "C 1500 SERIES", 'year' =&gt; "2005", 'engine' =&gt; "V8 5.7L (K)"), array('make' =&gt; "Nissan Pickup", 'model' =&gt; "D21 PICKUP", 'year' =&gt; "1993", 'engine' =&gt; "2.4 L"), array('make' =&gt; "TOYOTA CAMRY", 'model' =&gt; "LE", 'year' =&gt; "2001", 'engine' =&gt; "2.8L V6") ); </code></pre> <p>By defining your array like that, you can easily access the values at each key like this:</p> <pre><code>$mmy[0]['make']; // This returns Chevrolet Truck, for the first (0th) element of the array, and the 'make' key </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload