PHP Sorting Arrays
- What will be the output of the following PHP code ?
<?php
$Car = array("J" => "Jaguar", "L" => "Land Rover", "A" => "Audi", "M" => "Maseratti");
echo array_search("Maseratti", $Car);
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
The array_search() function searches for the element and returns the key of that element.
- What will be the output of the following PHP code ?
<?php
$Student = array("Ajit" => "23", "Rahul" => "22","Ats" => "23");
array_pop($Student);
print_r(array_change_key_case($Student, CASE_UPPER));
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
The array_change_key_case() function changes all keys in an array to lowercase or uppercase and arry_pop() removes last element.
- What will be the output of the following PHP code ?
<?php
$Color = array("R" => "Red", "G" => "Green", "B" => "Blue", "Y" => "Yellow");
$Result = array_flip($Color);
print_r($Result);
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
The array_flip() function flips/exchanges all keys with their associated values in an array.
- What will be the output of the following PHP code?
<?php
$Country = array("INDIA", "USA", "ENGLAND");
array_pop($Country);
$Country1 = array("ISRAEL");
$Country = array_merge($Country, $Country1);
print_r($Country);
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
array_merge() and array_pop() yields that result.
- What will be the output of the following PHP code ?
<?php
$Student = array("Ajit", "Rahul", "Ats", "Aju");
echo pos($Student);
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
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.