BigMonkeyHead
asked on
Size of multi-dimensional array
I know this is probably easy, but I haven't found the answer yet - I need to loop thru a 2-d array.
array(0, array('a','b','c','d','e') , 1, array('f','g','h','i','j') , 2, array('k','l','m','n','o') )
Is there an easy way to find out that my array is 3x5? I need to know the dimensions because I need to group the data together (a-e, f-j, and k-o) for display purposes.
array(0, array('a','b','c','d','e')
Is there an easy way to find out that my array is 3x5? I need to know the dimensions because I need to group the data together (a-e, f-j, and k-o) for display purposes.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
array(0, array('a','b','c','d','e') , 1, array('f','g','h','i','j') , 2, array('k','l','m','n','o') )
your array should be
array(array('a','b','c','d ','e'), array('f','g','h','i','j') , array('k','l','m','n','o') )
so, to loop through 2-d array :
$arr = array(array('a','b','c','d ','e'), array('f','g','h','i','j') , array('k','l','m','n','o') );
for ($i = 0; $i < count($arr); $i++)
{
for ($j = 0; $j < count($arr[$i]); $j++)
{
echo ' [' . $i . '][' . $j . '] = ' . $arr[$i][$j];
}
echo "<br>";
}
Bonmat86.
your array should be
array(array('a','b','c','d
so, to loop through 2-d array :
$arr = array(array('a','b','c','d
for ($i = 0; $i < count($arr); $i++)
{
for ($j = 0; $j < count($arr[$i]); $j++)
{
echo ' [' . $i . '][' . $j . '] = ' . $arr[$i][$j];
}
echo "<br>";
}
Bonmat86.
oops, sorry...
Bonmat86.
Bonmat86.
ASKER