array_diff_variation9.phpt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. --TEST--
  2. Test array_diff() function : usage variations - multidimensional arrays
  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
  7. * not present in any of the others arguments.
  8. * Source code: ext/standard/array.c
  9. */
  10. /*
  11. * Test how array_diff() compares multidimensional arrays
  12. */
  13. echo "*** Testing array_diff() : usage variations ***\n";
  14. $array1 = array('sub_array1' => array (1, 2, 3),
  15. 'sub_array2' => array ('a', 'b', 'c'));
  16. $array2 = array('sub_arraya' => array (1, 3, 5),
  17. 'sub_arrayb' => array ('a', 'z', 'y'));
  18. echo "-- Compare two 2-D arrays --\n";
  19. var_dump(array_diff($array1, $array2));
  20. var_dump(array_diff($array2, $array1));
  21. echo "\n-- Compare subarrays from two 2-D arrays --\n";
  22. var_dump(array_diff($array1['sub_array1'], $array2['sub_arraya']));
  23. var_dump(array_diff($array2['sub_arraya'], $array1['sub_array1']));
  24. var_dump(array_diff($array1['sub_array2'], $array2['sub_arrayb']));
  25. var_dump(array_diff($array2['sub_arrayb'], $array1['sub_array1']));
  26. echo "\n-- Compare a subarray from one 2-D array and one 2-D array --\n";
  27. var_dump(array_diff($array1['sub_array1'], $array2));
  28. var_dump(array_diff($array1, $array2['sub_arraya']));
  29. echo "Done";
  30. ?>
  31. --EXPECTF--
  32. *** Testing array_diff() : usage variations ***
  33. -- Compare two 2-D arrays --
  34. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  35. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  36. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  37. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  38. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  39. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  40. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  41. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  42. array(0) {
  43. }
  44. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  45. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  46. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  47. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  48. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  49. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  50. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  51. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  52. array(0) {
  53. }
  54. -- Compare subarrays from two 2-D arrays --
  55. array(1) {
  56. [1]=>
  57. int(2)
  58. }
  59. array(1) {
  60. [2]=>
  61. int(5)
  62. }
  63. array(2) {
  64. [1]=>
  65. string(1) "b"
  66. [2]=>
  67. string(1) "c"
  68. }
  69. array(3) {
  70. [0]=>
  71. string(1) "a"
  72. [1]=>
  73. string(1) "z"
  74. [2]=>
  75. string(1) "y"
  76. }
  77. -- Compare a subarray from one 2-D array and one 2-D array --
  78. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  79. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  80. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  81. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  82. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  83. array(3) {
  84. [0]=>
  85. int(1)
  86. [1]=>
  87. int(2)
  88. [2]=>
  89. int(3)
  90. }
  91. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  92. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  93. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  94. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  95. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  96. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  97. Notice: Array to string conversion in %sarray_diff_variation9.php on line %d
  98. array(2) {
  99. ["sub_array1"]=>
  100. array(3) {
  101. [0]=>
  102. int(1)
  103. [1]=>
  104. int(2)
  105. [2]=>
  106. int(3)
  107. }
  108. ["sub_array2"]=>
  109. array(3) {
  110. [0]=>
  111. string(1) "a"
  112. [1]=>
  113. string(1) "b"
  114. [2]=>
  115. string(1) "c"
  116. }
  117. }
  118. Done