Arrays - Study Mode
[#26] What will be the output of the following PHP code? <?php $age = array( "Peter" => "35" , "Ben" => "37" , "Joe" => "43" )
print_r(array_change_key_case( $age, CASE_UPPER ))
?>
Correct Answer
(C) Array ( [PETER] => 35 [BEN] => 37 [JOE] => 43 )
Explanation
Solution: The array_change_key_case() function changes all keys in an array to lowercase or uppercase.
[#27] What will be the output of the following PHP code? <?php $cars = array( "Volvo" , "BMW" , "Toyota" , "Honda" , "Mercedes" , "Opel " )
print_r(array_chunk( $cars, 2 ))
?>
Correct Answer
(D) Array ( [0] => Array ( [0] => Volvo [1] => BMW ) [1] => Array ( [0] => Toyota [1] => Honda ) [2] => Array ( [0] => Mercedes [1] => Opel ) )
Explanation
Solution: The array_chunk() function splits an array into chunks of new arrays.
[#28] What will be the output of the following PHP code? <?php $fname = array( "Peter" , "Ben" , "Joe" )
$age = array( "35" , "37" , "43" )
$c = array_combine( $fname, $age )
print_r( $c )
?>
Correct Answer
(B) Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
Explanation
Solution: The array_combine() function creates an array by using the elements from one “keys” array and one “values” array.
[#29] What will be the output of the following PHP code? <?php $cars = array( "Volvo" , "BMW" , "Toyota" )
echo "I like " . $cars [ 2 ] . ", " . $cars [ 1 ] . " and " . $cars [ 0 ] . "."
?>
Correct Answer
(D) I like Toyota, BMW and Volvo
Explanation
Solution: The order of elements defined.
[#30] What will be the output of the following PHP code? <?php $fname = array( "Peter" , "Ben" , "Joe" )
$age = array( "35" , "37" , "43" )
$c = array_combine( $age, $fname )
print_r( $c )
?>
Correct Answer
(D) Array ( [35] => Peter [37] => Ben [43] => Joe )
Explanation
Solution: Here “keys” array is $age and “values” array is $fname.