array_diff_variation6.phpt 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. --TEST--
  2. Test array_diff() function : usage variations - array containing duplicate keys and values
  3. --FILE--
  4. <?php
  5. /* Prototype : array array_diff(array $arr1, array $arr2 [, array ...])
  6. * Description: Returns the entries of $arr1 that have values which are not
  7. * present in any of the others arguments.
  8. * Source code: ext/standard/array.c
  9. */
  10. /*
  11. * Test that array_diff behaves as expected for comparing:
  12. * 1. the order of the array
  13. * 2. duplicate values
  14. * 3. duplicate key names
  15. */
  16. echo "*** Testing array_diff() : usage variations ***\n";
  17. $array_index = array('a', 'b', 'c', 0 => 'd', 'b'); //duplicate key (0), duplicate value (b)
  18. $array_assoc = array ('2' => 'c', //same key=>value pair, different order
  19. '1' => 'b',
  20. '0' => 'a',
  21. 'b' => '3', //key and value from array_index swapped
  22. 'c' => 2); //same as above, using integer
  23. var_dump(array_diff($array_index, $array_assoc));
  24. var_dump(array_diff($array_assoc, $array_index));
  25. echo "Done";
  26. ?>
  27. --EXPECTF--
  28. *** Testing array_diff() : usage variations ***
  29. array(1) {
  30. [0]=>
  31. string(1) "d"
  32. }
  33. array(3) {
  34. [0]=>
  35. string(1) "a"
  36. ["b"]=>
  37. string(1) "3"
  38. ["c"]=>
  39. int(2)
  40. }
  41. Done