array_push_variation6.phpt 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. --TEST--
  2. Test array_push() function : usage variations - array keys are different data types
  3. --FILE--
  4. <?php
  5. /* Prototype : int array_push(array $stack, mixed $var [, mixed $...])
  6. * Description: Pushes elements onto the end of the array
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Pass array_push arrays where the keys are different data types.
  11. */
  12. echo "*** Testing array_push() : usage variations ***\n";
  13. // Initialise function arguments not being substituted
  14. $var = 'value';
  15. //get an unset variable
  16. $unset_var = 10;
  17. unset ($unset_var);
  18. // heredoc string
  19. $heredoc = <<<EOT
  20. hello world
  21. EOT;
  22. // arrays of different data types as keys to be passed to $stack argument
  23. $inputs = array(
  24. // int data
  25. /*1*/ 'int' => array(
  26. 0 => 'zero',
  27. 1 => 'one',
  28. 12345 => 'positive',
  29. -2345 => 'negative',
  30. ),
  31. // float data
  32. /*2*/ 'float' => array(
  33. 10.5 => 'positive',
  34. -10.5 => 'negative',
  35. .5 => 'half',
  36. ),
  37. 'extreme floats' => array(
  38. 12.3456789000e10 => 'large',
  39. 12.3456789000E-10 => 'small',
  40. ),
  41. // null data
  42. /*3*/ 'null uppercase' => array(
  43. NULL => 'null 1',
  44. ),
  45. 'null lowercase' => array(
  46. null => 'null 2',
  47. ),
  48. // boolean data
  49. /*4*/ 'bool lowercase' => array(
  50. true => 'lowert',
  51. false => 'lowerf',
  52. ),
  53. 'bool uppercase' => array(
  54. TRUE => 'uppert',
  55. FALSE => 'upperf',
  56. ),
  57. // empty data
  58. /*5*/ 'empty double quotes' => array(
  59. "" => 'emptyd',
  60. ),
  61. 'empty single quotes' => array(
  62. '' => 'emptys',
  63. ),
  64. // string data
  65. /*6*/ 'string' => array(
  66. "stringd" => 'stringd',
  67. 'strings' => 'strings',
  68. $heredoc => 'stringh',
  69. ),
  70. // undefined data
  71. /*8*/ 'undefined' => array(
  72. @$undefined_var => 'undefined',
  73. ),
  74. // unset data
  75. /*9*/ 'unset' => array(
  76. @$unset_var => 'unset',
  77. ),
  78. );
  79. // loop through each sub-array of $inputs to check the behavior of array_push()
  80. $iterator = 1;
  81. foreach($inputs as $key => $input) {
  82. echo "\n-- Iteration $iterator : $key data --\n";
  83. echo "Before : ";
  84. var_dump(count($input));
  85. echo "After : ";
  86. var_dump( array_push($input, $var) );
  87. $iterator++;
  88. };
  89. echo "Done";
  90. ?>
  91. --EXPECTF--
  92. *** Testing array_push() : usage variations ***
  93. -- Iteration 1 : int data --
  94. Before : int(4)
  95. After : int(5)
  96. -- Iteration 2 : float data --
  97. Before : int(3)
  98. After : int(4)
  99. -- Iteration 3 : extreme floats data --
  100. Before : int(2)
  101. After : int(3)
  102. -- Iteration 4 : null uppercase data --
  103. Before : int(1)
  104. After : int(2)
  105. -- Iteration 5 : null lowercase data --
  106. Before : int(1)
  107. After : int(2)
  108. -- Iteration 6 : bool lowercase data --
  109. Before : int(2)
  110. After : int(3)
  111. -- Iteration 7 : bool uppercase data --
  112. Before : int(2)
  113. After : int(3)
  114. -- Iteration 8 : empty double quotes data --
  115. Before : int(1)
  116. After : int(2)
  117. -- Iteration 9 : empty single quotes data --
  118. Before : int(1)
  119. After : int(2)
  120. -- Iteration 10 : string data --
  121. Before : int(3)
  122. After : int(4)
  123. -- Iteration 11 : undefined data --
  124. Before : int(1)
  125. After : int(2)
  126. -- Iteration 12 : unset data --
  127. Before : int(1)
  128. After : int(2)
  129. Done