PHP Arrays输出理解

Hi I have recently just started PHP and I'm currently trying to learn arrays. Below is an array im looking at and don't quite understand how it outputs the columns of the array. I don't understand how $row and $col suddenly just output the first 2 columns of the array and also what would need to do to output the 3rd column.

$shop = array( array("rose", 1.25 , 15),
               array("daisy", 0.75 , 25),
               array("orchid", 1.15 , 7) 
             ); 

             echo "<h1>Using loops to display array elements</h1>";

echo "<ol>";
for ($row = 0; $row < 3; $row++)
{
    echo "<li><b>The row number $row</b></li>";
    echo "<ul>";

    for ($col = 0; $col < 3; $col++)
    {
    echo $shop [$row] [$col];
    }

    echo "</ul>";
    echo "</li>";
}
echo "</ol>";

Actually, the three rows ARE displayed when you execute the script. When tested with php 5.5, the output was:

<h1>Using loops to display array elements</h1>
<ol>
  <li><b>The row number 0</b></li>
  <ul>rose1.2515</ul></li>
  <li><b>The row number 1</b></li>
  <ul>daisy0.7525</ul></li>
  <li><b>The row number 2</b></li>
  <ul>orchid1.157</ul></li>
</ol>

The problem here is your HTML syntax. If you look closely, you can see that every <ul> block are followed by a </li>, which is never opened by an expected <li>.

To respect the standard, you should also put every element of each <ul> you generate with a <li> block.

Result should look something like this:

<h1>Using loops to display array elements</h1>
<ol>
  <li><b>The row number 0</b></li>
  <ul>
    <li>rose</li>
    <li>1.25</li>
    <li>15</li>
  </ul>
  <li><b>The row number 1</b></li>
  <ul>
    <li>daisy</li>
    <li>0.75</li>
    <li>25</li>
  </ul>
  <li><b>The row number 2</b></li>
  <ul>
    <li>orchid</li>
    <li>1.15</li>
    <li>7</li>
  </ul>
</ol>

Hope this helps!

Edit: You could also use the PHP native function array_column, here's the documentation link.

It does output all three columns, but a bit mashed up. Try adding a space or something between the values:

echo $shop[$row][$col] . '&nbsp;';

Or display it in a table:

echo "<table border='1'>";
for ($row = 0; $row < 3; $row++)
{
    echo "<tr><td>Row number $row</td>";

    for ($col = 0; $col < 3; $col++)
    {
        echo '<td>' . $shop[$row][$col] . '</td>';
    }
    echo "</tr>";
}
echo "</table>";
$shop = array( array("rose", 1.25 , 15),
               array("daisy", 0.75 , 25),
               array("orchid", 1.15 , 7) 
             ); 

             echo "<h1>Using loops to display array elements</h1>";

echo "<ol>";
for ($row = 0; $row < count($row); $row++)
{
    echo "<li><b>The row number $row</b></li>";
    echo "<ul>";

    for ($col = 0; $col < count($shop[$row]); $col++)
    {
        echo "<li>";
        echo $shop [$row] [$col];
        echo "</li>";
    }

    echo "</ul>";
    echo "</li>";
}
echo "</ol>";