array_unshift_variation9.phpt 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. --TEST--
  2. Test array_unshift() function : usage variations - heredoc strings for 'var' argument
  3. --FILE--
  4. <?php
  5. /* Prototype : int array_unshift(array $array, mixed $var [, mixed ...])
  6. * Description: Pushes elements onto the beginning of the array
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Testing the functionality of array_unshift() by passing different
  11. * heredoc strings for $var argument that is prepended to the array
  12. * passed through $array argument
  13. */
  14. echo "*** Testing array_unshift() : heredoc strings for \$var argument ***\n";
  15. // heredoc with empty value
  16. $empty_string = <<<EOT
  17. EOT;
  18. // heredoc with blank line
  19. $blank_line = <<<EOT
  20. EOT;
  21. // heredoc with multiline string
  22. $multiline_string = <<<EOT
  23. hello world
  24. The big brown fox jumped over;
  25. the lazy dog
  26. This is a double quoted string
  27. EOT;
  28. // heredoc with different whitespaces
  29. $diff_whitespaces = <<<EOT
  30. hello\r world\t
  31. 1111\t\t != 2222\v\v
  32. heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces
  33. EOT;
  34. // heredoc with numeric values
  35. $numeric_string = <<<EOT
  36. 11 < 12. 123 >22
  37. 2222 != 1111.\t 0000 = 0000\n
  38. EOT;
  39. // heredoc with quote chars & slash
  40. $quote_char_string = <<<EOT
  41. This's a string with quotes:
  42. "strings in double quote";
  43. 'strings in single quote';
  44. this\line is single quoted /with\slashes
  45. EOT;
  46. // array to be passed to $array argument
  47. $array = array('f' => "first", "s" => 'second', 1, 2.222);
  48. // different heredoc strings to be passed to $var argument
  49. $vars = array(
  50. $empty_string,
  51. $blank_line,
  52. $multiline_string,
  53. $diff_whitespaces,
  54. $numeric_string,
  55. $quote_char_string
  56. );
  57. // loop through the various elements of $arrays to test array_unshift()
  58. $iterator = 1;
  59. foreach($vars as $var) {
  60. echo "-- Iteration $iterator --\n";
  61. $temp_array = $array; // assign $array to another temporary $temp_array
  62. /* with default argument */
  63. // returns element count in the resulting array after arguments are pushed to
  64. // beginning of the given array
  65. var_dump( array_unshift($temp_array, $var) );
  66. // dump the resulting array
  67. var_dump($temp_array);
  68. /* with all possible arguments */
  69. // returns element count in the resulting array after arguments are pushed to
  70. // beginning of the given array
  71. $temp_array = $array;
  72. var_dump( array_unshift($temp_array, $var, "hello", 'world') );
  73. // dump the resulting array
  74. var_dump($temp_array);
  75. $iterator++;
  76. }
  77. echo "Done";
  78. ?>
  79. --EXPECTF--
  80. *** Testing array_unshift() : heredoc strings for $var argument ***
  81. -- Iteration 1 --
  82. int(5)
  83. array(5) {
  84. [0]=>
  85. string(0) ""
  86. ["f"]=>
  87. string(5) "first"
  88. ["s"]=>
  89. string(6) "second"
  90. [1]=>
  91. int(1)
  92. [2]=>
  93. float(2.222)
  94. }
  95. int(7)
  96. array(7) {
  97. [0]=>
  98. string(0) ""
  99. [1]=>
  100. string(5) "hello"
  101. [2]=>
  102. string(5) "world"
  103. ["f"]=>
  104. string(5) "first"
  105. ["s"]=>
  106. string(6) "second"
  107. [3]=>
  108. int(1)
  109. [4]=>
  110. float(2.222)
  111. }
  112. -- Iteration 2 --
  113. int(5)
  114. array(5) {
  115. [0]=>
  116. string(1) "
  117. "
  118. ["f"]=>
  119. string(5) "first"
  120. ["s"]=>
  121. string(6) "second"
  122. [1]=>
  123. int(1)
  124. [2]=>
  125. float(2.222)
  126. }
  127. int(7)
  128. array(7) {
  129. [0]=>
  130. string(1) "
  131. "
  132. [1]=>
  133. string(5) "hello"
  134. [2]=>
  135. string(5) "world"
  136. ["f"]=>
  137. string(5) "first"
  138. ["s"]=>
  139. string(6) "second"
  140. [3]=>
  141. int(1)
  142. [4]=>
  143. float(2.222)
  144. }
  145. -- Iteration 3 --
  146. int(5)
  147. array(5) {
  148. [0]=>
  149. string(86) "hello world
  150. The big brown fox jumped over;
  151. the lazy dog
  152. This is a double quoted string"
  153. ["f"]=>
  154. string(5) "first"
  155. ["s"]=>
  156. string(6) "second"
  157. [1]=>
  158. int(1)
  159. [2]=>
  160. float(2.222)
  161. }
  162. int(7)
  163. array(7) {
  164. [0]=>
  165. string(86) "hello world
  166. The big brown fox jumped over;
  167. the lazy dog
  168. This is a double quoted string"
  169. [1]=>
  170. string(5) "hello"
  171. [2]=>
  172. string(5) "world"
  173. ["f"]=>
  174. string(5) "first"
  175. ["s"]=>
  176. string(6) "second"
  177. [3]=>
  178. int(1)
  179. [4]=>
  180. float(2.222)
  181. }
  182. -- Iteration 4 --
  183. int(5)
  184. array(5) {
  185. [0]=>
  186. string(88) "hello world
  187. 1111 != 2222
  188. heredoc
  189. double quoted string. with different white spaces"
  190. ["f"]=>
  191. string(5) "first"
  192. ["s"]=>
  193. string(6) "second"
  194. [1]=>
  195. int(1)
  196. [2]=>
  197. float(2.222)
  198. }
  199. int(7)
  200. array(7) {
  201. [0]=>
  202. string(88) "hello world
  203. 1111 != 2222
  204. heredoc
  205. double quoted string. with different white spaces"
  206. [1]=>
  207. string(5) "hello"
  208. [2]=>
  209. string(5) "world"
  210. ["f"]=>
  211. string(5) "first"
  212. ["s"]=>
  213. string(6) "second"
  214. [3]=>
  215. int(1)
  216. [4]=>
  217. float(2.222)
  218. }
  219. -- Iteration 5 --
  220. int(5)
  221. array(5) {
  222. [0]=>
  223. string(44) "11 < 12. 123 >22
  224. 2222 != 1111. 0000 = 0000
  225. "
  226. ["f"]=>
  227. string(5) "first"
  228. ["s"]=>
  229. string(6) "second"
  230. [1]=>
  231. int(1)
  232. [2]=>
  233. float(2.222)
  234. }
  235. int(7)
  236. array(7) {
  237. [0]=>
  238. string(44) "11 < 12. 123 >22
  239. 2222 != 1111. 0000 = 0000
  240. "
  241. [1]=>
  242. string(5) "hello"
  243. [2]=>
  244. string(5) "world"
  245. ["f"]=>
  246. string(5) "first"
  247. ["s"]=>
  248. string(6) "second"
  249. [3]=>
  250. int(1)
  251. [4]=>
  252. float(2.222)
  253. }
  254. -- Iteration 6 --
  255. int(5)
  256. array(5) {
  257. [0]=>
  258. string(123) "This's a string with quotes:
  259. "strings in double quote";
  260. 'strings in single quote';
  261. this\line is single quoted /with\slashes"
  262. ["f"]=>
  263. string(5) "first"
  264. ["s"]=>
  265. string(6) "second"
  266. [1]=>
  267. int(1)
  268. [2]=>
  269. float(2.222)
  270. }
  271. int(7)
  272. array(7) {
  273. [0]=>
  274. string(123) "This's a string with quotes:
  275. "strings in double quote";
  276. 'strings in single quote';
  277. this\line is single quoted /with\slashes"
  278. [1]=>
  279. string(5) "hello"
  280. [2]=>
  281. string(5) "world"
  282. ["f"]=>
  283. string(5) "first"
  284. ["s"]=>
  285. string(6) "second"
  286. [3]=>
  287. int(1)
  288. [4]=>
  289. float(2.222)
  290. }
  291. Done