array_fill_variation4.phpt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. --TEST--
  2. Test array_fill() function : usage variations - using return value of array_fill for 'val' argument
  3. --FILE--
  4. <?php
  5. /* Prototype : proto array array_fill(int start_key, int num, mixed val)
  6. * Description: Create an array containing num elements starting with index start_key each initialized to val
  7. * Source code: ext/standard/array.c
  8. */
  9. /* passing array_fill() as the 'val' argument in array_fill() function */
  10. echo "*** Testing array_fill() : variation ***\n";
  11. $start_key = 0;
  12. $num = 2;
  13. $heredoc = <<<HERE_DOC
  14. Hello
  15. HERE_DOC;
  16. // array of possible valid values for 'val' argument
  17. $values = array (
  18. /* 1 */ NULL,
  19. 0,
  20. 1,
  21. /* 4 */ 1.0,
  22. 'hi',
  23. "hi",
  24. /* 7 */ $heredoc
  25. );
  26. echo "*** Filling 2 dimensional array with all basic valid values ***\n";
  27. $counter = 1;
  28. for($i =0; $i < count($values); $i ++)
  29. {
  30. echo "-- Iteration $counter --\n";
  31. $val = $values[$i];
  32. var_dump( array_fill($start_key,$num,array_fill($start_key,$num,$val)) );
  33. $counter++;
  34. }
  35. echo "Done";
  36. ?>
  37. --EXPECTF--
  38. *** Testing array_fill() : variation ***
  39. *** Filling 2 dimensional array with all basic valid values ***
  40. -- Iteration 1 --
  41. array(2) {
  42. [0]=>
  43. array(2) {
  44. [0]=>
  45. NULL
  46. [1]=>
  47. NULL
  48. }
  49. [1]=>
  50. array(2) {
  51. [0]=>
  52. NULL
  53. [1]=>
  54. NULL
  55. }
  56. }
  57. -- Iteration 2 --
  58. array(2) {
  59. [0]=>
  60. array(2) {
  61. [0]=>
  62. int(0)
  63. [1]=>
  64. int(0)
  65. }
  66. [1]=>
  67. array(2) {
  68. [0]=>
  69. int(0)
  70. [1]=>
  71. int(0)
  72. }
  73. }
  74. -- Iteration 3 --
  75. array(2) {
  76. [0]=>
  77. array(2) {
  78. [0]=>
  79. int(1)
  80. [1]=>
  81. int(1)
  82. }
  83. [1]=>
  84. array(2) {
  85. [0]=>
  86. int(1)
  87. [1]=>
  88. int(1)
  89. }
  90. }
  91. -- Iteration 4 --
  92. array(2) {
  93. [0]=>
  94. array(2) {
  95. [0]=>
  96. float(1)
  97. [1]=>
  98. float(1)
  99. }
  100. [1]=>
  101. array(2) {
  102. [0]=>
  103. float(1)
  104. [1]=>
  105. float(1)
  106. }
  107. }
  108. -- Iteration 5 --
  109. array(2) {
  110. [0]=>
  111. array(2) {
  112. [0]=>
  113. string(2) "hi"
  114. [1]=>
  115. string(2) "hi"
  116. }
  117. [1]=>
  118. array(2) {
  119. [0]=>
  120. string(2) "hi"
  121. [1]=>
  122. string(2) "hi"
  123. }
  124. }
  125. -- Iteration 6 --
  126. array(2) {
  127. [0]=>
  128. array(2) {
  129. [0]=>
  130. string(2) "hi"
  131. [1]=>
  132. string(2) "hi"
  133. }
  134. [1]=>
  135. array(2) {
  136. [0]=>
  137. string(2) "hi"
  138. [1]=>
  139. string(2) "hi"
  140. }
  141. }
  142. -- Iteration 7 --
  143. array(2) {
  144. [0]=>
  145. array(2) {
  146. [0]=>
  147. string(5) "Hello"
  148. [1]=>
  149. string(5) "Hello"
  150. }
  151. [1]=>
  152. array(2) {
  153. [0]=>
  154. string(5) "Hello"
  155. [1]=>
  156. string(5) "Hello"
  157. }
  158. }
  159. Done