Arrays - Study Mode
[#51] What will be the output of the following PHP code? <?php $arr = array ( "picture1.JPG" , "picture2.jpg" , "Picture10.jpg" , "picture20.jpg" )
sort( $arr )
print_r( $arr )
?>
Correct Answer
(C) Array ( [0] => Picture10.jpg [1] => picture1.JPG [2] => picture2.jpg [3] => picture20.jpg )
Explanation
Solution: While sorting each character is compared with the others and sorted using ascii values therefore we the sorted array to be like option c.
[#52] What will be the output of the following PHP code? <?php $face = array ( "A" , "J" , "Q" , "K" )
$number = array ( "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" )
$cards = array_merge ( $face, $number )
print_r ( $cards )
?>
Correct Answer
(A) Array ( [0] => A [1] => J [2] => Q [3] => K [4] => 2 [5] => 3 [6] => 4 [7] => 5 [8] => 6 [9] => 7 [10] => 8 [11] => 9 [12] => 10 )
Explanation
Solution: The resulting array will begin with the first input array parameter, appending each subsequent array parameter in the order of appearance.
[#53] What will be the output of the following PHP code? <?php $fruits = array ( "apple" , "mango" , "peach" , "pear" , "orange" )
$subset = array_slice ( $fruits, 2 )
print_r ( $subset )
?>
Correct Answer
(D) Array ( [0] => peach [1] => pear [2] => orange )
Explanation
Solution: The array_slice() function returns a section of an array based on a starting and ending offset value.