logo       

Re: Array Question: msg#02350

php.general

Subject: Re: Array Question


On Thursday, April 18, 2002, at 04:38 PM, Jason Lam wrote:

$arr2 is a 2d array.

$arr1[0] = 1;
$arr1[1] = 10;
$arr2[0] = $arr1;
print $arr2[0][1];

Result will be 10

But,

$arr1[0] = 1;
$arr1[1] = 10;
$arr2[0] = $arr1;
$arr3 = each($arr2);
print $arr3[1];

What are you expecting? Check out the documentation for each() at http://www.php.net/manual/en/function.each.php

At this point $arr3 should look like this (I think, but try print_r($arr3) to be sure):

{
0 => 0,
1 => array (
0 => array (
0 => 1,
1 => 10
)
),
key => 0,
value => array (
0 => array (
0 => 1,
1 => 10
)
)
}


Result is not 10. So, function "each" is not taking the whole $arr2[0]
out......

My question is what function should I use to iterate array elements (with
arrays in it)?


How about foreach()?

-Steve

Jay


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise