Arrays - Study Mode
[#16] What will be the output of the following PHP code? <?php $state = array ( "Karnataka" , "Goa" , "Tamil Nadu" , "Andhra Pradesh" )
echo (array_search ( "Tamil Nadu" , $state ) )
?>
Correct Answer
(D) 2
Explanation
Solution: The array_search() function searches an array for a specified value, returning its key if located and FALSE otherwise.
[#17] What will be the output of the following PHP code? <?php $fruits = array ( "apple" , "orange" , "banana" )
echo (next( $fruits ))
echo (next( $fruits ))
?>
Correct Answer
(A) orangebanana
Explanation
Solution: The next() function returns the array value residing at the position immediately following that of the current array pointer.
[#18] What will be the output of the following PHP code? <?php $fruits = array ( "apple" , "orange" , array ( "pear" , "mango" ) , "banana" )
echo (count( $fruits, 1 ))
?>
Correct Answer
(D) 6
Explanation
Solution: The array entity holding pear and mango is counted as an item, just as its contents are.
[#19] What will be the output of the following PHP code ? <?php $a1 = array ( "a" => "red" , "b" => "green" , "c" => "blue" , "d" => "yellow" )
$a2 = array ("e" => "red" , "f" => "green" , "g" => "blue" )
$result = array_intersect ( $a1, $a2 )
print_r ( $result )
?>
Correct Answer
(A) Array ( [a] => red [b] => green [c] => blue )
Explanation
Solution: The array_intersect() function compares the values of two (or more) arrays, and returns the matches.
[#20] What will be the output of the following PHP code ? <?php $a = array( 12 , 5 , 2 )
echo( array_product ( $a ))
?>
Correct Answer
(B) 120
Explanation
Solution: The array_product() function calculates and returns the product of an array.