array_column_variant.phpt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. --TEST--
  2. Test array_column() function: variant functionality
  3. --FILE--
  4. <?php
  5. /* Array from Bug Request #64493 test script */
  6. $rows = array(
  7. 456 => array('id' => '3', 'title' => 'Foo', 'date' => '2013-03-25'),
  8. 457 => array('id' => '5', 'title' => 'Bar', 'date' => '2012-05-20'),
  9. );
  10. echo "-- pass null as second parameter to get back all columns indexed by third parameter --\n";
  11. var_dump(array_column($rows, null, 'id'));
  12. echo "-- pass null as second parameter and bogus third param to get back zero-indexed array of all columns --\n";
  13. var_dump(array_column($rows, null, 'foo'));
  14. echo "-- pass null as second parameter and no third param to get back array_values(input) --\n";
  15. var_dump(array_column($rows, null));
  16. echo "Done\n";
  17. --EXPECTF--
  18. -- pass null as second parameter to get back all columns indexed by third parameter --
  19. array(2) {
  20. [3]=>
  21. array(3) {
  22. ["id"]=>
  23. string(1) "3"
  24. ["title"]=>
  25. string(3) "Foo"
  26. ["date"]=>
  27. string(10) "2013-03-25"
  28. }
  29. [5]=>
  30. array(3) {
  31. ["id"]=>
  32. string(1) "5"
  33. ["title"]=>
  34. string(3) "Bar"
  35. ["date"]=>
  36. string(10) "2012-05-20"
  37. }
  38. }
  39. -- pass null as second parameter and bogus third param to get back zero-indexed array of all columns --
  40. array(2) {
  41. [0]=>
  42. array(3) {
  43. ["id"]=>
  44. string(1) "3"
  45. ["title"]=>
  46. string(3) "Foo"
  47. ["date"]=>
  48. string(10) "2013-03-25"
  49. }
  50. [1]=>
  51. array(3) {
  52. ["id"]=>
  53. string(1) "5"
  54. ["title"]=>
  55. string(3) "Bar"
  56. ["date"]=>
  57. string(10) "2012-05-20"
  58. }
  59. }
  60. -- pass null as second parameter and no third param to get back array_values(input) --
  61. array(2) {
  62. [0]=>
  63. array(3) {
  64. ["id"]=>
  65. string(1) "3"
  66. ["title"]=>
  67. string(3) "Foo"
  68. ["date"]=>
  69. string(10) "2013-03-25"
  70. }
  71. [1]=>
  72. array(3) {
  73. ["id"]=>
  74. string(1) "5"
  75. ["title"]=>
  76. string(3) "Bar"
  77. ["date"]=>
  78. string(10) "2012-05-20"
  79. }
  80. }
  81. Done