shuffle_variation5.phpt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. --TEST--
  2. Test shuffle() function : usage variation - arrays with diff heredoc strings
  3. --FILE--
  4. <?php
  5. /* Prototype : bool shuffle(array $array_arg)
  6. * Description: Randomly shuffle the contents of an array
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Test behaviour of shuffle() when an array of heredoc strings is passed to
  11. * 'array_arg' argument of the function
  12. */
  13. echo "*** Testing shuffle() : with array containing heredoc strings ***\n";
  14. // defining different heredoc strings
  15. $empty_heredoc = <<<EOT
  16. EOT;
  17. $heredoc_with_newline = <<<EOT
  18. \n
  19. EOT;
  20. $heredoc_with_characters = <<<EOT
  21. first line of heredoc string
  22. second line of heredoc string
  23. third line of heredocstring
  24. EOT;
  25. $heredoc_with_newline_and_tabs = <<<EOT
  26. hello\tworld\nhello\nworld\n
  27. EOT;
  28. $heredoc_with_alphanumerics = <<<EOT
  29. hello123world456
  30. 1234hello\t1234
  31. EOT;
  32. $heredoc_with_embedded_nulls = <<<EOT
  33. hello\0world\0hello
  34. \0hello\0
  35. EOT;
  36. // defining array with values as heredoc strings
  37. $heredoc_array = array(
  38. $empty_heredoc,
  39. $heredoc_with_newline,
  40. $heredoc_with_characters,
  41. $heredoc_with_newline_and_tabs,
  42. $heredoc_with_alphanumerics,
  43. $heredoc_with_embedded_nulls
  44. );
  45. // defining array with keys as heredoc strings
  46. $heredoc_asso_array = array(
  47. $empty_heredoc => "heredoc1",
  48. $heredoc_with_newline => "heredoc2",
  49. $heredoc_with_characters => "heredoc3",
  50. $heredoc_with_newline_and_tabs => "heredoc3",
  51. $heredoc_with_alphanumerics => "heredoc4",
  52. $heredoc_with_embedded_nulls => "heredoc5"
  53. );
  54. // test shuffle() with array containing heredoc strings as values
  55. echo "\n-- with array of heredoc strings --\n";
  56. var_dump( shuffle($heredoc_array) );
  57. echo "\nThe output array is:\n";
  58. var_dump( $heredoc_array );
  59. // test shuffle() with array containing heredoc strings as its keys
  60. echo "\n-- with array having heredoc strings as keys --\n";
  61. var_dump( shuffle($heredoc_asso_array) );
  62. echo "\nThe output array is:\n";
  63. var_dump( $heredoc_asso_array );
  64. echo "Done";
  65. ?>
  66. --EXPECTREGEX--
  67. \*\*\* Testing shuffle\(\) : with array containing heredoc strings \*\*\*
  68. -- with array of heredoc strings --
  69. bool\(true\)
  70. The output array is:
  71. array\(6\) {
  72. \[0\]=>
  73. string\([0-9]*\) "[0-9 a-z \n \0 \t]*"
  74. \[1\]=>
  75. string\([0-9]*\) "[0-9 a-z \n \0 \t]*"
  76. \[2\]=>
  77. string\([0-9]*\) "[0-9 a-z \n \0 \t]*"
  78. \[3\]=>
  79. string\([0-9]*\) "[0-9 a-z \n \0 \t]*"
  80. \[4\]=>
  81. string\([0-9]*\) "[0-9 a-z \n \0 \t]*"
  82. \[5\]=>
  83. string\([0-9]*\) "[0-9 a-z \n \0 \t]*"
  84. }
  85. -- with array having heredoc strings as keys --
  86. bool\(true\)
  87. The output array is:
  88. array\(6\) {
  89. \[0\]=>
  90. string\(8\) "[heredoc 1-5]*"
  91. \[1\]=>
  92. string\(8\) "[heredoc 1-5]*"
  93. \[2\]=>
  94. string\(8\) "[heredoc 1-5]*"
  95. \[3\]=>
  96. string\(8\) "[heredoc 1-5]*"
  97. \[4\]=>
  98. string\(8\) "[heredoc 1-5]*"
  99. \[5\]=>
  100. string\(8\) "[heredoc 1-5]*"
  101. }
  102. Done