Arrays - Study Mode
[#11] Which in-built function will add a value to the end of an array?
Correct Answer
(D) array_push()
Explanation
Solution: array_push adds a value to the end of an array, returning the total count of elementsin the array after the new value has been added.
[#12] Which function can be used to move the pointer to the previous array position?
Correct Answer
(C) prev()
[#13] Which function returns an array consisting of associative key/value pairs?
Correct Answer
(C) array_count_values()
[#14] Which of the following are correct ways of creating an array? 1. state[0] = “karnataka”
2. $state[] = array(“karnataka”)
3. $state[0] = “karnataka”
4. $state = array(“karnataka”)
Correct Answer
(A) 3 and 4
Explanation
Solution: A variable name should start with $ symbol which is not present in i) and you need not put the square brackets when you use the array() constructor.
[#15] What will be the output of the following php code? <?php $states = array( "karnataka" => array( "population" => "11,35,000" , "captial" => "Bangalore" ) , "Tamil Nadu" => array( "population" => "17,90,000" , "captial" => "Chennai" ) )
echo $states [ "karnataka" ][ "population" ]
?>
Correct Answer
(B) 11,35,000
Explanation
Solution: Treat states as a multidimensional array and accordingly traverse it to get the value.