Next Nov 1 PreviousSorting is the key
Consider the following program:
<?php
$a = array(
"key1" => "c",
"key2" => "a",
"key3" => "d",
"key4" => "b"
);
sort($a);
echo $a["key1"];
?>
What will be the output of this script:
A: "a"
B: "b"
C: "c"
D: "d"
E: Nothing or a notice
Answer
When you use sort()
only the array values will be sorted and the existing keys will be discarded. So after the call to sort()
on line 10 the array will not have an entry "key1" anymore and nothing or a notice about an undefined key will be outputted. So answer E is correct.