1--TEST--
2Test array_pad() function : usage variations - different arrays for 'input' argument
3--FILE--
4<?php
5/*
6* Passing different arrays to $input argument and testing whether
7* array_pad() behaves in an expected way with the other arguments passed to the function.
8* The $pad_size and $pad_value arguments passed are fixed values.
9*/
10
11echo "*** Testing array_pad() : Passing different arrays to \$input argument ***\n";
12
13/* Different heredoc strings */
14
15// heredoc with blank line
16$blank_line = <<<EOT
17
18
19EOT;
20
21// heredoc with multiline string
22$multiline_string = <<<EOT
23hello world
24The big brown fox jumped over;
25the lazy dog
26This is a double quoted string
27EOT;
28
29// heredoc with different whitespaces
30$diff_whitespaces = <<<EOT
31hello\r world\t
321111\t\t != 2222\v\v
33heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces
34EOT;
35
36// heredoc with quoted strings and numeric values
37$numeric_string = <<<EOT
3811 < 12. 123 >22
39'single quoted string'
40"double quoted string"
412222 != 1111.\t 0000 = 0000\n
42EOT;
43
44// different arrays to be passed to $input argument
45$inputs = array (
46/*1*/  array(1, 2), // with default keys and numeric values
47       array(1.1, 2.2), // with default keys & float values
48       array(false,true), // with default keys and boolean values
49       array(), // empty array
50/*5*/  array(NULL), // with NULL
51       array("a\v\f", "aaaa\r", "b\tbbb", "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"),  // with double quoted strings
52       array('a\v\f', 'aaaa\r', 'b\tbbb', '\[\]\!\@\#\$\%\^\&\*\(\)\{\}'),  // with single quoted strings
53       array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string),  // with heredocs
54
55       // associative arrays
56/*9*/  array(1 => "one", 2 => "two", 3 => "three"),  // explicit numeric keys, string values
57       array("one" => 1, "two" => 2, "three" => 3 ),  // string keys & numeric values
58       array( 1 => 10, 2 => 20, 4 => 40, 3 => 30),  // explicit numeric keys and numeric values
59       array( "one" => "ten", "two" => "twenty", "three" => "thirty"),  // string key/value
60       array("one" => 1, 2 => "two", 4 => "four"),  //mixed
61
62       // associative array, containing null/empty/boolean values as key/value
63/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null),
64       array(true => "true", false => "false", "false" => false, "true" => true),
65       array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''),
66       array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true),
67       array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6),
68
69       // array with repetitive keys
70/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3)
71);
72
73// initialize the $pad_size and $pad_value arguments
74$pad_size = 6;
75$pad_value = "HELLO";
76
77// loop through each sub-array within $inputs to check the behavior of array_pad()
78$iterator = 1;
79foreach($inputs as $input) {
80  echo "-- Iteration $iterator --\n";
81  var_dump( array_pad($input, $pad_size, $pad_value) );  // positive 'pad_size'
82  var_dump( array_pad($input, -$pad_size, $pad_value) );  // negative 'pad_size'
83  $iterator++;
84};
85
86echo "Done";
87?>
88--EXPECT--
89*** Testing array_pad() : Passing different arrays to $input argument ***
90-- Iteration 1 --
91array(6) {
92  [0]=>
93  int(1)
94  [1]=>
95  int(2)
96  [2]=>
97  string(5) "HELLO"
98  [3]=>
99  string(5) "HELLO"
100  [4]=>
101  string(5) "HELLO"
102  [5]=>
103  string(5) "HELLO"
104}
105array(6) {
106  [0]=>
107  string(5) "HELLO"
108  [1]=>
109  string(5) "HELLO"
110  [2]=>
111  string(5) "HELLO"
112  [3]=>
113  string(5) "HELLO"
114  [4]=>
115  int(1)
116  [5]=>
117  int(2)
118}
119-- Iteration 2 --
120array(6) {
121  [0]=>
122  float(1.1)
123  [1]=>
124  float(2.2)
125  [2]=>
126  string(5) "HELLO"
127  [3]=>
128  string(5) "HELLO"
129  [4]=>
130  string(5) "HELLO"
131  [5]=>
132  string(5) "HELLO"
133}
134array(6) {
135  [0]=>
136  string(5) "HELLO"
137  [1]=>
138  string(5) "HELLO"
139  [2]=>
140  string(5) "HELLO"
141  [3]=>
142  string(5) "HELLO"
143  [4]=>
144  float(1.1)
145  [5]=>
146  float(2.2)
147}
148-- Iteration 3 --
149array(6) {
150  [0]=>
151  bool(false)
152  [1]=>
153  bool(true)
154  [2]=>
155  string(5) "HELLO"
156  [3]=>
157  string(5) "HELLO"
158  [4]=>
159  string(5) "HELLO"
160  [5]=>
161  string(5) "HELLO"
162}
163array(6) {
164  [0]=>
165  string(5) "HELLO"
166  [1]=>
167  string(5) "HELLO"
168  [2]=>
169  string(5) "HELLO"
170  [3]=>
171  string(5) "HELLO"
172  [4]=>
173  bool(false)
174  [5]=>
175  bool(true)
176}
177-- Iteration 4 --
178array(6) {
179  [0]=>
180  string(5) "HELLO"
181  [1]=>
182  string(5) "HELLO"
183  [2]=>
184  string(5) "HELLO"
185  [3]=>
186  string(5) "HELLO"
187  [4]=>
188  string(5) "HELLO"
189  [5]=>
190  string(5) "HELLO"
191}
192array(6) {
193  [0]=>
194  string(5) "HELLO"
195  [1]=>
196  string(5) "HELLO"
197  [2]=>
198  string(5) "HELLO"
199  [3]=>
200  string(5) "HELLO"
201  [4]=>
202  string(5) "HELLO"
203  [5]=>
204  string(5) "HELLO"
205}
206-- Iteration 5 --
207array(6) {
208  [0]=>
209  NULL
210  [1]=>
211  string(5) "HELLO"
212  [2]=>
213  string(5) "HELLO"
214  [3]=>
215  string(5) "HELLO"
216  [4]=>
217  string(5) "HELLO"
218  [5]=>
219  string(5) "HELLO"
220}
221array(6) {
222  [0]=>
223  string(5) "HELLO"
224  [1]=>
225  string(5) "HELLO"
226  [2]=>
227  string(5) "HELLO"
228  [3]=>
229  string(5) "HELLO"
230  [4]=>
231  string(5) "HELLO"
232  [5]=>
233  NULL
234}
235-- Iteration 6 --
236array(6) {
237  [0]=>
238  string(3) "a"
239  [1]=>
240  string(5) "aaaa
240"
241  [2]=>
242  string(5) "b	bbb"
243  [3]=>
244  string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}"
245  [4]=>
246  string(5) "HELLO"
247  [5]=>
248  string(5) "HELLO"
249}
250array(6) {
251  [0]=>
252  string(5) "HELLO"
253  [1]=>
254  string(5) "HELLO"
255  [2]=>
256  string(3) "a"
257  [3]=>
258  string(5) "aaaa
258"
259  [4]=>
260  string(5) "b	bbb"
261  [5]=>
262  string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}"
263}
264-- Iteration 7 --
265array(6) {
266  [0]=>
267  string(5) "a\v\f"
268  [1]=>
269  string(6) "aaaa\r"
270  [2]=>
271  string(6) "b\tbbb"
272  [3]=>
273  string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"
274  [4]=>
275  string(5) "HELLO"
276  [5]=>
277  string(5) "HELLO"
278}
279array(6) {
280  [0]=>
281  string(5) "HELLO"
282  [1]=>
283  string(5) "HELLO"
284  [2]=>
285  string(5) "a\v\f"
286  [3]=>
287  string(6) "aaaa\r"
288  [4]=>
289  string(6) "b\tbbb"
290  [5]=>
291  string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"
292}
293-- Iteration 8 --
294array(6) {
295  ["h1"]=>
296  string(1) "
297"
298  ["h2"]=>
299  string(86) "hello world
300The big brown fox jumped over;
301the lazy dog
302This is a double quoted string"
303  ["h3"]=>
304  string(88) "hello
304 world
3051111		 != 2222
306heredoc
307double quoted string. withdifferentwhitespaces"
308  [0]=>
309  string(90) "11 < 12. 123 >22
310'single quoted string'
311"double quoted string"
3122222 != 1111.	 0000 = 0000
313"
314  [1]=>
315  string(5) "HELLO"
316  [2]=>
317  string(5) "HELLO"
318}
319array(6) {
320  [0]=>
321  string(5) "HELLO"
322  [1]=>
323  string(5) "HELLO"
324  ["h1"]=>
325  string(1) "
326"
327  ["h2"]=>
328  string(86) "hello world
329The big brown fox jumped over;
330the lazy dog
331This is a double quoted string"
332  ["h3"]=>
333  string(88) "hello
333 world
3341111		 != 2222
335heredoc
336double quoted string. withdifferentwhitespaces"
337  [2]=>
338  string(90) "11 < 12. 123 >22
339'single quoted string'
340"double quoted string"
3412222 != 1111.	 0000 = 0000
342"
343}
344-- Iteration 9 --
345array(6) {
346  [0]=>
347  string(3) "one"
348  [1]=>
349  string(3) "two"
350  [2]=>
351  string(5) "three"
352  [3]=>
353  string(5) "HELLO"
354  [4]=>
355  string(5) "HELLO"
356  [5]=>
357  string(5) "HELLO"
358}
359array(6) {
360  [0]=>
361  string(5) "HELLO"
362  [1]=>
363  string(5) "HELLO"
364  [2]=>
365  string(5) "HELLO"
366  [3]=>
367  string(3) "one"
368  [4]=>
369  string(3) "two"
370  [5]=>
371  string(5) "three"
372}
373-- Iteration 10 --
374array(6) {
375  ["one"]=>
376  int(1)
377  ["two"]=>
378  int(2)
379  ["three"]=>
380  int(3)
381  [0]=>
382  string(5) "HELLO"
383  [1]=>
384  string(5) "HELLO"
385  [2]=>
386  string(5) "HELLO"
387}
388array(6) {
389  [0]=>
390  string(5) "HELLO"
391  [1]=>
392  string(5) "HELLO"
393  [2]=>
394  string(5) "HELLO"
395  ["one"]=>
396  int(1)
397  ["two"]=>
398  int(2)
399  ["three"]=>
400  int(3)
401}
402-- Iteration 11 --
403array(6) {
404  [0]=>
405  int(10)
406  [1]=>
407  int(20)
408  [2]=>
409  int(40)
410  [3]=>
411  int(30)
412  [4]=>
413  string(5) "HELLO"
414  [5]=>
415  string(5) "HELLO"
416}
417array(6) {
418  [0]=>
419  string(5) "HELLO"
420  [1]=>
421  string(5) "HELLO"
422  [2]=>
423  int(10)
424  [3]=>
425  int(20)
426  [4]=>
427  int(40)
428  [5]=>
429  int(30)
430}
431-- Iteration 12 --
432array(6) {
433  ["one"]=>
434  string(3) "ten"
435  ["two"]=>
436  string(6) "twenty"
437  ["three"]=>
438  string(6) "thirty"
439  [0]=>
440  string(5) "HELLO"
441  [1]=>
442  string(5) "HELLO"
443  [2]=>
444  string(5) "HELLO"
445}
446array(6) {
447  [0]=>
448  string(5) "HELLO"
449  [1]=>
450  string(5) "HELLO"
451  [2]=>
452  string(5) "HELLO"
453  ["one"]=>
454  string(3) "ten"
455  ["two"]=>
456  string(6) "twenty"
457  ["three"]=>
458  string(6) "thirty"
459}
460-- Iteration 13 --
461array(6) {
462  ["one"]=>
463  int(1)
464  [0]=>
465  string(3) "two"
466  [1]=>
467  string(4) "four"
468  [2]=>
469  string(5) "HELLO"
470  [3]=>
471  string(5) "HELLO"
472  [4]=>
473  string(5) "HELLO"
474}
475array(6) {
476  [0]=>
477  string(5) "HELLO"
478  [1]=>
479  string(5) "HELLO"
480  [2]=>
481  string(5) "HELLO"
482  ["one"]=>
483  int(1)
484  [3]=>
485  string(3) "two"
486  [4]=>
487  string(4) "four"
488}
489-- Iteration 14 --
490array(6) {
491  [""]=>
492  string(4) "null"
493  ["NULL"]=>
494  NULL
495  ["null"]=>
496  NULL
497  [0]=>
498  string(5) "HELLO"
499  [1]=>
500  string(5) "HELLO"
501  [2]=>
502  string(5) "HELLO"
503}
504array(6) {
505  [0]=>
506  string(5) "HELLO"
507  [1]=>
508  string(5) "HELLO"
509  [2]=>
510  string(5) "HELLO"
511  [""]=>
512  string(4) "null"
513  ["NULL"]=>
514  NULL
515  ["null"]=>
516  NULL
517}
518-- Iteration 15 --
519array(6) {
520  [0]=>
521  string(4) "true"
522  [1]=>
523  string(5) "false"
524  ["false"]=>
525  bool(false)
526  ["true"]=>
527  bool(true)
528  [2]=>
529  string(5) "HELLO"
530  [3]=>
531  string(5) "HELLO"
532}
533array(6) {
534  [0]=>
535  string(5) "HELLO"
536  [1]=>
537  string(5) "HELLO"
538  [2]=>
539  string(4) "true"
540  [3]=>
541  string(5) "false"
542  ["false"]=>
543  bool(false)
544  ["true"]=>
545  bool(true)
546}
547-- Iteration 16 --
548array(6) {
549  [""]=>
550  string(6) "emptys"
551  ["emptyd"]=>
552  string(0) ""
553  ["emptys"]=>
554  string(0) ""
555  [0]=>
556  string(5) "HELLO"
557  [1]=>
558  string(5) "HELLO"
559  [2]=>
560  string(5) "HELLO"
561}
562array(6) {
563  [0]=>
564  string(5) "HELLO"
565  [1]=>
566  string(5) "HELLO"
567  [2]=>
568  string(5) "HELLO"
569  [""]=>
570  string(6) "emptys"
571  ["emptyd"]=>
572  string(0) ""
573  ["emptys"]=>
574  string(0) ""
575}
576-- Iteration 17 --
577array(6) {
578  [1]=>
579  string(0) ""
580  [2]=>
581  string(0) ""
582  [3]=>
583  NULL
584  [4]=>
585  NULL
586  [5]=>
587  bool(false)
588  [6]=>
589  bool(true)
590}
591array(6) {
592  [1]=>
593  string(0) ""
594  [2]=>
595  string(0) ""
596  [3]=>
597  NULL
598  [4]=>
599  NULL
600  [5]=>
601  bool(false)
602  [6]=>
603  bool(true)
604}
605-- Iteration 18 --
606array(6) {
607  [""]=>
608  int(4)
609  [0]=>
610  int(5)
611  [1]=>
612  int(6)
613  [2]=>
614  string(5) "HELLO"
615  [3]=>
616  string(5) "HELLO"
617  [4]=>
618  string(5) "HELLO"
619}
620array(6) {
621  [0]=>
622  string(5) "HELLO"
623  [1]=>
624  string(5) "HELLO"
625  [2]=>
626  string(5) "HELLO"
627  [""]=>
628  int(4)
629  [3]=>
630  int(5)
631  [4]=>
632  int(6)
633}
634-- Iteration 19 --
635array(6) {
636  ["One"]=>
637  int(10)
638  ["two"]=>
639  int(20)
640  ["three"]=>
641  int(3)
642  [0]=>
643  string(5) "HELLO"
644  [1]=>
645  string(5) "HELLO"
646  [2]=>
647  string(5) "HELLO"
648}
649array(6) {
650  [0]=>
651  string(5) "HELLO"
652  [1]=>
653  string(5) "HELLO"
654  [2]=>
655  string(5) "HELLO"
656  ["One"]=>
657  int(10)
658  ["two"]=>
659  int(20)
660  ["three"]=>
661  int(3)
662}
663Done
664