Home » PHP » PHP Sorting Arrays » Question
  1. What will be the output of the following PHP code?
    <?php
    $City1 = array ("Noida", "Delhi", "Chennai", "Greenville", "Branford");
    $City2 = array ("Chennai", "Derby", "Enfield", "Delhi", "Greenville");
    $inter = array_intersect ($City1, $City2);
    print_r ($inter);
    ?>
    1. Array
      (
      [1] => Delhi
      [2] => Chennai
      [3] => Greenville
      [4] => Branford
      )
    2. Array
      (
      [2] => Chennai
      [3] => Greenville
      )
    3. Array
      (
      [1] => Delhi
      [2] => Noida
      [3] => Chennai
      [4] => Greenville
      )
    4. Array
      (
      [1] => Delhi
      [2] => Chennai
      [3] => Greenville
      )
    5. None of these
Correct Option: D

The array_intersect() function returns a key preserved array consisting only of those values present in the first array that are also present in each of the other input arrays.



Your comments will be displayed only after manual approval.