Arrays - Study Mode
[#21] What will be the output of the following PHP code ? <?php $a = array( "a" => "Jaguar" , "b" => "Land Rover" , "c" => "Audi" , "d" => "Maseratti" )
echo array_search( "Audi" , $a )
?>
Correct Answer
(C) c
Explanation
Solution: The array_search() function searches for the element and returns the key of that element.
[#22] What will be the output of the following PHP code ? <?php $city_west = array( "NYC" , "London" )
$city_east = array( "Mumbai" , "Beijing" )
print_r( array_replace ( $city_west, $city_east ))
?>
Correct Answer
(D) Array ( [0] => Mumbai [1] => Beijing )
Explanation
Solution: The array_replace() function replaces the values of the first array with the values from following arrays
[#23] What will be the output of the following PHP code ? <?php $people = array( "Peter" , "Susan" , "Edmund" , "Lucy" )
echo pos( $people )
?>
Correct Answer
(B) Peter
Explanation
Solution: The pos() function returns the value of the current element in an array, and since no operation has been done, the current element is the first element.
[#24] What will be the output of the following PHP code ? <?php $number = range( 0 , 5 )
print_r ( $number )
?>
Correct Answer
(A) Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 )
Explanation
Solution: The range() function creates an array containing a range of elements.
[#25] What will be the output of the following PHP code ? <?php $array = array( "red" , "green" )
array_push( $array, "blue" , "yellow" )
print_r( $array )
?>
Correct Answer
(A) Array ( [0] => red [1] => green [2] => blue [3] => yellow )
Explanation
Solution: The array_push() function inserts one or more elements to the end of an array.