PHP array of arrays

Multiple choice question

PHP arrays are a useful way to handle series of variables. An array can hold another array.
What will be the output of the following code?

$tops = array(
0=>array("user_id"=>34, "user_name"=>"Dan"),
1=>array("user_id"=>35, "user_name"=>"Ben"),
2=>array("user_id"=>36, "user_name"=>"Roy"));

foreach ($tops as $key=>$top){
$top["user_id"] = $key;
}
echo " {$tops[0]["user_id"]} ";

wrong

0

correct

34

Feedback: The code in the "foreach" loop changed only the copies of the values of the $tops array. In order to be able to directly modify array elements within the loop precede $value with '&'. In that case the value will be assigned by reference. For example, the 'foreach' loop statement should be change to: 'foreach ($tops as $key=>&$top)'.

wrong

Syntax Error

wrong

NULL

Feedback:

0
Your rating: None
This question is part of the following quizzes