array_fill_basic.phpt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. --TEST--
  2. Test array_fill() function : basic functionality
  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. echo "*** Testing array_fill() : basic functionality ***\n";
  10. // calling the array_fill with all possible valid values for 'val' argument
  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.5,
  22. 'hi',
  23. "hi",
  24. /* 7 */ $heredoc
  25. );
  26. $counter = 1;
  27. for($i = 0; $i < count($values); $i ++)
  28. {
  29. echo "-- Iteration $counter --\n";
  30. $val = $values[$i];
  31. var_dump( array_fill($start_key,$num,$val) );
  32. $counter++;
  33. }
  34. echo "Done";
  35. ?>
  36. --EXPECTF--
  37. *** Testing array_fill() : basic functionality ***
  38. -- Iteration 1 --
  39. array(2) {
  40. [0]=>
  41. NULL
  42. [1]=>
  43. NULL
  44. }
  45. -- Iteration 2 --
  46. array(2) {
  47. [0]=>
  48. int(0)
  49. [1]=>
  50. int(0)
  51. }
  52. -- Iteration 3 --
  53. array(2) {
  54. [0]=>
  55. int(1)
  56. [1]=>
  57. int(1)
  58. }
  59. -- Iteration 4 --
  60. array(2) {
  61. [0]=>
  62. float(1.5)
  63. [1]=>
  64. float(1.5)
  65. }
  66. -- Iteration 5 --
  67. array(2) {
  68. [0]=>
  69. string(2) "hi"
  70. [1]=>
  71. string(2) "hi"
  72. }
  73. -- Iteration 6 --
  74. array(2) {
  75. [0]=>
  76. string(2) "hi"
  77. [1]=>
  78. string(2) "hi"
  79. }
  80. -- Iteration 7 --
  81. array(2) {
  82. [0]=>
  83. string(5) "Hello"
  84. [1]=>
  85. string(5) "Hello"
  86. }
  87. Done