Arrays - Study Mode

[#36] What will be the output of the following PHP code? <?php $place = array( "NYC" , "LA" , "Paris" )
array_pop( $place )
$place1 = array( "Paris" )
$place = array_merge( $place, $place1 )
print_r( $place )
?>
Correct Answer

(A) Array ( [0] => LA [1] => Paris [2] => Paris )

Explanation

Solution: array_merge() and array_pop() yields that result.

[#37] What will be the output of the following PHP code ? <?php $age = array ( "Harry" => "21" , "Ron" => "23" , "Malfoy" => "21" )
array_change_key_case ( $age, CASE_UPPER )
array_pop ( $age )
print_r ( $age )
?>
Correct Answer

(C) Array ( [HARRY] => 21 [RON] => 23 )

Explanation

Solution: The array_change_key_case() function changes all keys in an array to lowercase or uppercase and arry_pop() removes last element

[#38] What will be the output of the following PHP code ? <?php $a1 = array ( "a" => "red" , "b" => "green" , "c" => "blue" , "d" => "yellow" )
$result = array_flip ( $a1 )
print_r ( $result )
?>
Correct Answer

(C) Array ( [red] => a [green] => b [blue] => c [yellow] => d )

Explanation

Solution: The array_flip() function flips/exchanges all keys with their associated values in an array.

[#39] What will be the output of the following PHP code? <?php $fruits = array ( "apple" , "mango" , "peach" , "pear" , "orange" )
$subset = array_splice ( $fruits, 2 )
print_r ( $fruits )
?>
Correct Answer

(C) Array ( [0] => apple [1] => mango )

Explanation

Solution: The array_splice() function removes all elements of an array found within a specified range.

[#40] What will be the output of the following PHP code? <?php $number = array ( "4" , "hello" , 2 )
echo (array_sum ( $number ))
?>
Correct Answer

(D) 6

Explanation

Solution: The array_sum() function add all the values of the input array together, returning the final sum. If a string datatype is found, it’ll be ignored.