PHP Arrays


  1. What will be the output of the following PHP code?
    <?php
    $Color = array("Green", "White", "Green", "Red", "Yellow", "White");
    print_r(array_count_values($Color));
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    The array_count_values() function counts all the values of an array.


  1. What will be the output of the following PHP code?
    <?php
    $flowre1 = array("001"=>"Daffodil", "002"=>"Dahlia", "003"=>"Daisy", "004"=>"Dianella", "005"=>"Delphinium");
    $flowre2 = array("006"=>"Daffodil", "007"=>"Dahlia", "008"=>"Daisy");
    $Res = array_diff($flowre1, $flowre2);
    print_r($Res);
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    The array_diff() function compares the values of two (or more) arrays, and returns the differences.



  1. What will be the output of the following PHP code?
    <?php
    $Name1 = array_fill(2, 3, "Ajit Kumar Gupta");
    $Name2 = array_fill(1, 2, "Ats Yogi");
    print_r($Name1);
    print_r($Name2);
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    The array_fill() function fills an array with values.


  1. What will be the output of the following PHP code?
    <?php
    $Student1 = array("Neha", "Rahul");
    $Student2 = array("Sujit", "Vivek", "Rohan");
    print_r(array_merge($Student1, $Student2));
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    The array_merge() function merges one or more arrays into one array.



  1. What will be the output of the following PHP code?
    <?php
    $City = array("A"=>"Chennai", "B"=>"Noida", "C"=>"Delhi");
    echo array_shift($City);
    print_r ($City);
    ?>











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    The array_shift() function removes the first element from an array, and returns the value of the removed element.