PHP Sorting Arrays


  1. 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);
    ?>











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


  1. 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));
    ?>











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



  1. 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);
    ?>











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


  1. 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);
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    array_merge() and array_pop() yields that result.



  1. What will be the output of the following PHP code ?
    <?php
    $Student = array("Ajit", "Rahul", "Ats", "Aju");
    echo pos($Student);
    ?>











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