Check out Scrivo

Do you want to try out Scrivo? Then here's a demo for you that does not just get your feet wet but lets you plunge right in.

Contact us

For more information, please contact us. We're happy to help you out!

Next Nov 1 Previous

Sorting 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.