PHP Sorting Arrays
- 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
$First = array("Ajit", "Rahul");
$Second = array("Ats", "Aju");
$Third = array_merge($First, $Second);
$Fourth = array("001", "002", "003", "004");
$Result = array_combine($Fourth, $Third);
print_r($Result);
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Basic combined application of array_combine() and array_merge().
- What will be the output of the following PHP code?
<?php
$First = array("Rahul","Ajit","Ats","Rahul","Ats","Sujit");
$Second = array("Rahul","Rahul","Ajit","Rahul","Aju","Sujit");
$Third = array_combine($First,$Second);
print_r(array_count_values($Third));
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
The array_count_values() function counts all the values of an array and array_combine() combines arrays.
- What will be the output of the following PHP code?
<?php
$First = array("001" => "Ajit", "002" => "Rahul", "003" => "Ats", "004" => "Aju");
$Second = array("005" => "Ajit", "006" => "Rahul", "007" => "Ats", "008" => "Sujit");
$Third = array("009" => "Sujit");
$Forth = array_merge($Second, $Third);
$Result = array_diff($First, $Forth);
print_r($Result);
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
The array_diff() function compares the values of two (or more) arrays, and returns the differences. This function compares the values of two (or more) arrays, and return an array that contains the entries from array1 that are not present in other arrays (array2, array3, etc).
- What will be the output of the following PHP code ?
<?php
$name = array("Abhay", "Sujit");
array_push($name, "Neha", "Reema");
print_r($name);
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
The array_push() function inserts one or more elements to the end of an array.