array_values_variation3.phpt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. --TEST--
  2. Test array_values() function : usage variations - array keys different data types
  3. --FILE--
  4. <?php
  5. /* Prototype : array array_values(array $input)
  6. * Description: Return just the values from the input array
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Pass arrays where the keys are different data types as $input argument
  11. * to array_values() to test behaviour
  12. */
  13. echo "*** Testing array_values() : usage variations ***\n";
  14. //get an unset variable
  15. $unset_var = 10;
  16. unset ($unset_var);
  17. // heredoc string
  18. $heredoc = <<<EOT
  19. hello world
  20. EOT;
  21. // unexpected values to be passed as $input
  22. $inputs = array(
  23. // int data
  24. /*1*/ 'int' => array(
  25. 0 => 'zero',
  26. 1 => 'one',
  27. 12345 => 'positive',
  28. -2345 => 'negative',
  29. ),
  30. // float data
  31. /*2*/ 'float' => array(
  32. 10.5 => 'positive',
  33. -10.5 => 'negative',
  34. .5 => 'half',
  35. ),
  36. /*3*/ 'extreme floats' => array(
  37. 12.3456789000e10 => 'large',
  38. 12.3456789000E-10 => 'small',
  39. ),
  40. // null data
  41. /*4*/ 'null uppercase' => array(
  42. NULL => 'null 1',
  43. ),
  44. /*5*/ 'null lowercase' => array(
  45. null => 'null 2',
  46. ),
  47. // boolean data
  48. /*6*/ 'bool lowercase' => array(
  49. true => 'lowert',
  50. false => 'lowerf',
  51. ),
  52. /*7*/ 'bool uppercase' => array(
  53. TRUE => 'uppert',
  54. FALSE => 'upperf',
  55. ),
  56. // empty data
  57. /*8*/ 'empty double quotes' => array(
  58. "" => 'emptyd',
  59. ),
  60. /*9*/ 'empty single quotes' => array(
  61. '' => 'emptys',
  62. ),
  63. // string data
  64. /*10*/ 'string' => array(
  65. "stringd" => 'stringd',
  66. 'strings' => 'strings',
  67. $heredoc => 'stringh',
  68. ),
  69. // undefined data
  70. /*11*/ 'undefined' => array(
  71. @$undefined_var => 'undefined',
  72. ),
  73. // unset data
  74. /*12*/ 'unset' => array(
  75. @$unset_var => 'unset',
  76. ),
  77. );
  78. // loop through each element of $inputs to check the behavior of array_values()
  79. $iterator = 1;
  80. foreach($inputs as $key => $input) {
  81. echo "\n-- Iteration $iterator: $key data --\n";
  82. var_dump( array_values($input) );
  83. $iterator++;
  84. };
  85. echo "Done";
  86. ?>
  87. --EXPECTF--
  88. *** Testing array_values() : usage variations ***
  89. -- Iteration 1: int data --
  90. array(4) {
  91. [0]=>
  92. string(4) "zero"
  93. [1]=>
  94. string(3) "one"
  95. [2]=>
  96. string(8) "positive"
  97. [3]=>
  98. string(8) "negative"
  99. }
  100. -- Iteration 2: float data --
  101. array(3) {
  102. [0]=>
  103. string(8) "positive"
  104. [1]=>
  105. string(8) "negative"
  106. [2]=>
  107. string(4) "half"
  108. }
  109. -- Iteration 3: extreme floats data --
  110. array(2) {
  111. [0]=>
  112. string(5) "large"
  113. [1]=>
  114. string(5) "small"
  115. }
  116. -- Iteration 4: null uppercase data --
  117. array(1) {
  118. [0]=>
  119. string(6) "null 1"
  120. }
  121. -- Iteration 5: null lowercase data --
  122. array(1) {
  123. [0]=>
  124. string(6) "null 2"
  125. }
  126. -- Iteration 6: bool lowercase data --
  127. array(2) {
  128. [0]=>
  129. string(6) "lowert"
  130. [1]=>
  131. string(6) "lowerf"
  132. }
  133. -- Iteration 7: bool uppercase data --
  134. array(2) {
  135. [0]=>
  136. string(6) "uppert"
  137. [1]=>
  138. string(6) "upperf"
  139. }
  140. -- Iteration 8: empty double quotes data --
  141. array(1) {
  142. [0]=>
  143. string(6) "emptyd"
  144. }
  145. -- Iteration 9: empty single quotes data --
  146. array(1) {
  147. [0]=>
  148. string(6) "emptys"
  149. }
  150. -- Iteration 10: string data --
  151. array(3) {
  152. [0]=>
  153. string(7) "stringd"
  154. [1]=>
  155. string(7) "strings"
  156. [2]=>
  157. string(7) "stringh"
  158. }
  159. -- Iteration 11: undefined data --
  160. array(1) {
  161. [0]=>
  162. string(9) "undefined"
  163. }
  164. -- Iteration 12: unset data --
  165. array(1) {
  166. [0]=>
  167. string(5) "unset"
  168. }
  169. Done