PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

How can I display values in a two dimensional array?


Thanks for your question.

You were along the right lines with the foreach command - you simply need to nest a foreach within another foreach, like this:

<?php
$myarray 
= array();
$myarray[0] = array(1,2,3,4);
$myarray[1] = array(5,6,7,8);
//
foreach($myarray as $v) {
foreach(
$v as $myv) {
echo 
"$myv<br>";
}
}
//prints 1 through 8 on screen
?>



More arrays PHP Questions

How can I mix up the order of values in an array?
How can I loop through the members of an array?
How do I remove and view the last element of an array?
How do I add to the end of an array and know how large the array is?
How do I sort the members of an array by value?