1

I have a multi-dimensional array that I need to loop through and create <td></td> for each value of the inner array. Can someone show me how to do it? Thanks. Here is the array:

Array
(
    [Nov 18, 2011] => Array
        (
            [0] => C
            [1] => I
            [2] => S
        )

    [Nov 22, 2011] => Array
        (
            [0] => C
            [1] => S
        )

)

I need to retrieve the C, I, and S values. Thank you.

1

2 Answers 2

7

Given that your data is validly stored in $dates and we want an HTML table with new row for each date:

echo '<table>';
foreach( $dates as $date ) {
  echo "<tr>";
  foreach( $date as $value ) {
    echo "<td>".$value."</td>";
  }
  echo "</tr>";
}
echo '</table>';

For details, see: http://codepad.org/TbfuR2ud

Sign up to request clarification or add additional context in comments.

2 Comments

Looks like you got in there first with that... +1
Thanks guys. You make it look so easy!
2
foreach ($array as $date) {
  foreach ($date as $val) {
    echo "<td>$val</td>\n";
  }
}

You may want to echo some <tr>s in the outer loop, to separate them into rows.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.