Home » PHP » PHP Sorting Arrays » Question
  1. What will be the output of the following PHP code?
    <?php
    $subject = array('a' => 'Math', 'b' => 'Science', 'c'=> 'Geography');
    asort($subject);
    foreach ($subject as $key => $val)
    {
    echo "$key = $val";
    echo "\n";
    }
    ?>
    1. Error
    2. c = Geography
      a = Math
      b = Science
    3. Nothing
    4. a = Math
      b = Science
      c = Geography
    5. None of these
Correct Option: B

The function asort() sorts the array in ascending order, except that the key/value corresponding is maintained.



Your comments will be displayed only after manual approval.