1--TEST--
2Test array_unshift() function : usage variations - all possible values for 'var' argument
3--FILE--
4<?php
5/*
6 * Testing array_unshift() by giving all the possible values for $var argument
7*/
8
9echo "*** Testing array_unshift() : all possible values for \$var argument ***\n";
10
11// array to be passed to $array argument
12$array = array('f' => "first", "s" => 'second', 1, 2.222);
13
14// get a class
15class classA
16{
17  public function __toString() {
18    return "Class A object";
19  }
20}
21
22// get a resource variable
23$fp = fopen(__FILE__, "r");
24
25// heredoc string
26$heredoc = <<<EOT
27hello world
28EOT;
29
30// get an unset variable
31$unset_var = 10;
32unset ($unset_var);
33
34// different types of values to be passed to $var argument
35$vars = array(
36
37       // int data
38/*1*/  0,
39       1,
40       12345,
41       -2345,
42
43       // float data
44/*5*/  10.5,
45       -10.5,
46       12.3456789000e10,
47       12.3456789000E-10,
48       .5,
49
50       // array data
51/*10*/ array(),
52       array(0),
53       array(1),
54       array(1, 2),
55       array('color' => 'red', 'item' => 'pen'),
56
57       // null data
58/*15*/ NULL,
59       null,
60
61       // boolean data
62/*17*/ true,
63       false,
64       TRUE,
65       FALSE,
66
67       // empty data
68/*21*/ "",
69       '',
70
71       // string data
72/*23*/ "string",
73       'string',
74       $heredoc,
75
76       // object data
77/*26*/ new classA(),
78
79       // undefined data
80       @$undefined_var,
81
82       // unset data
83       @$unset_var,
84
85       // resource variable
86/*29*/ $fp
87);
88
89// loop through each element of $vars to check the functionality of array_unshift()
90$iterator = 1;
91foreach($vars as $var) {
92  echo "-- Iteration $iterator --\n";
93  $temp_array = $array;
94
95  /* with default argument */
96  // returns element count in the resulting array after arguments are pushed to
97  // beginning of the given array
98  var_dump( array_unshift($temp_array, $var) );
99
100  // dump the resulting array
101  var_dump($temp_array);
102
103  /* with optional arguments */
104  // returns element count in the resulting array after arguments are pushed to
105  // beginning of the given array
106  $temp_array = $array;
107  var_dump( array_unshift($temp_array, $var, "hello", 'world') );
108
109  // dump the resulting array
110  var_dump($temp_array);
111  $iterator++;
112}
113
114// close the file resource used
115fclose($fp);
116
117echo "Done";
118?>
119--EXPECTF--
120*** Testing array_unshift() : all possible values for $var argument ***
121-- Iteration 1 --
122int(5)
123array(5) {
124  [0]=>
125  int(0)
126  ["f"]=>
127  string(5) "first"
128  ["s"]=>
129  string(6) "second"
130  [1]=>
131  int(1)
132  [2]=>
133  float(2.222)
134}
135int(7)
136array(7) {
137  [0]=>
138  int(0)
139  [1]=>
140  string(5) "hello"
141  [2]=>
142  string(5) "world"
143  ["f"]=>
144  string(5) "first"
145  ["s"]=>
146  string(6) "second"
147  [3]=>
148  int(1)
149  [4]=>
150  float(2.222)
151}
152-- Iteration 2 --
153int(5)
154array(5) {
155  [0]=>
156  int(1)
157  ["f"]=>
158  string(5) "first"
159  ["s"]=>
160  string(6) "second"
161  [1]=>
162  int(1)
163  [2]=>
164  float(2.222)
165}
166int(7)
167array(7) {
168  [0]=>
169  int(1)
170  [1]=>
171  string(5) "hello"
172  [2]=>
173  string(5) "world"
174  ["f"]=>
175  string(5) "first"
176  ["s"]=>
177  string(6) "second"
178  [3]=>
179  int(1)
180  [4]=>
181  float(2.222)
182}
183-- Iteration 3 --
184int(5)
185array(5) {
186  [0]=>
187  int(12345)
188  ["f"]=>
189  string(5) "first"
190  ["s"]=>
191  string(6) "second"
192  [1]=>
193  int(1)
194  [2]=>
195  float(2.222)
196}
197int(7)
198array(7) {
199  [0]=>
200  int(12345)
201  [1]=>
202  string(5) "hello"
203  [2]=>
204  string(5) "world"
205  ["f"]=>
206  string(5) "first"
207  ["s"]=>
208  string(6) "second"
209  [3]=>
210  int(1)
211  [4]=>
212  float(2.222)
213}
214-- Iteration 4 --
215int(5)
216array(5) {
217  [0]=>
218  int(-2345)
219  ["f"]=>
220  string(5) "first"
221  ["s"]=>
222  string(6) "second"
223  [1]=>
224  int(1)
225  [2]=>
226  float(2.222)
227}
228int(7)
229array(7) {
230  [0]=>
231  int(-2345)
232  [1]=>
233  string(5) "hello"
234  [2]=>
235  string(5) "world"
236  ["f"]=>
237  string(5) "first"
238  ["s"]=>
239  string(6) "second"
240  [3]=>
241  int(1)
242  [4]=>
243  float(2.222)
244}
245-- Iteration 5 --
246int(5)
247array(5) {
248  [0]=>
249  float(10.5)
250  ["f"]=>
251  string(5) "first"
252  ["s"]=>
253  string(6) "second"
254  [1]=>
255  int(1)
256  [2]=>
257  float(2.222)
258}
259int(7)
260array(7) {
261  [0]=>
262  float(10.5)
263  [1]=>
264  string(5) "hello"
265  [2]=>
266  string(5) "world"
267  ["f"]=>
268  string(5) "first"
269  ["s"]=>
270  string(6) "second"
271  [3]=>
272  int(1)
273  [4]=>
274  float(2.222)
275}
276-- Iteration 6 --
277int(5)
278array(5) {
279  [0]=>
280  float(-10.5)
281  ["f"]=>
282  string(5) "first"
283  ["s"]=>
284  string(6) "second"
285  [1]=>
286  int(1)
287  [2]=>
288  float(2.222)
289}
290int(7)
291array(7) {
292  [0]=>
293  float(-10.5)
294  [1]=>
295  string(5) "hello"
296  [2]=>
297  string(5) "world"
298  ["f"]=>
299  string(5) "first"
300  ["s"]=>
301  string(6) "second"
302  [3]=>
303  int(1)
304  [4]=>
305  float(2.222)
306}
307-- Iteration 7 --
308int(5)
309array(5) {
310  [0]=>
311  float(123456789000)
312  ["f"]=>
313  string(5) "first"
314  ["s"]=>
315  string(6) "second"
316  [1]=>
317  int(1)
318  [2]=>
319  float(2.222)
320}
321int(7)
322array(7) {
323  [0]=>
324  float(123456789000)
325  [1]=>
326  string(5) "hello"
327  [2]=>
328  string(5) "world"
329  ["f"]=>
330  string(5) "first"
331  ["s"]=>
332  string(6) "second"
333  [3]=>
334  int(1)
335  [4]=>
336  float(2.222)
337}
338-- Iteration 8 --
339int(5)
340array(5) {
341  [0]=>
342  float(1.23456789E-9)
343  ["f"]=>
344  string(5) "first"
345  ["s"]=>
346  string(6) "second"
347  [1]=>
348  int(1)
349  [2]=>
350  float(2.222)
351}
352int(7)
353array(7) {
354  [0]=>
355  float(1.23456789E-9)
356  [1]=>
357  string(5) "hello"
358  [2]=>
359  string(5) "world"
360  ["f"]=>
361  string(5) "first"
362  ["s"]=>
363  string(6) "second"
364  [3]=>
365  int(1)
366  [4]=>
367  float(2.222)
368}
369-- Iteration 9 --
370int(5)
371array(5) {
372  [0]=>
373  float(0.5)
374  ["f"]=>
375  string(5) "first"
376  ["s"]=>
377  string(6) "second"
378  [1]=>
379  int(1)
380  [2]=>
381  float(2.222)
382}
383int(7)
384array(7) {
385  [0]=>
386  float(0.5)
387  [1]=>
388  string(5) "hello"
389  [2]=>
390  string(5) "world"
391  ["f"]=>
392  string(5) "first"
393  ["s"]=>
394  string(6) "second"
395  [3]=>
396  int(1)
397  [4]=>
398  float(2.222)
399}
400-- Iteration 10 --
401int(5)
402array(5) {
403  [0]=>
404  array(0) {
405  }
406  ["f"]=>
407  string(5) "first"
408  ["s"]=>
409  string(6) "second"
410  [1]=>
411  int(1)
412  [2]=>
413  float(2.222)
414}
415int(7)
416array(7) {
417  [0]=>
418  array(0) {
419  }
420  [1]=>
421  string(5) "hello"
422  [2]=>
423  string(5) "world"
424  ["f"]=>
425  string(5) "first"
426  ["s"]=>
427  string(6) "second"
428  [3]=>
429  int(1)
430  [4]=>
431  float(2.222)
432}
433-- Iteration 11 --
434int(5)
435array(5) {
436  [0]=>
437  array(1) {
438    [0]=>
439    int(0)
440  }
441  ["f"]=>
442  string(5) "first"
443  ["s"]=>
444  string(6) "second"
445  [1]=>
446  int(1)
447  [2]=>
448  float(2.222)
449}
450int(7)
451array(7) {
452  [0]=>
453  array(1) {
454    [0]=>
455    int(0)
456  }
457  [1]=>
458  string(5) "hello"
459  [2]=>
460  string(5) "world"
461  ["f"]=>
462  string(5) "first"
463  ["s"]=>
464  string(6) "second"
465  [3]=>
466  int(1)
467  [4]=>
468  float(2.222)
469}
470-- Iteration 12 --
471int(5)
472array(5) {
473  [0]=>
474  array(1) {
475    [0]=>
476    int(1)
477  }
478  ["f"]=>
479  string(5) "first"
480  ["s"]=>
481  string(6) "second"
482  [1]=>
483  int(1)
484  [2]=>
485  float(2.222)
486}
487int(7)
488array(7) {
489  [0]=>
490  array(1) {
491    [0]=>
492    int(1)
493  }
494  [1]=>
495  string(5) "hello"
496  [2]=>
497  string(5) "world"
498  ["f"]=>
499  string(5) "first"
500  ["s"]=>
501  string(6) "second"
502  [3]=>
503  int(1)
504  [4]=>
505  float(2.222)
506}
507-- Iteration 13 --
508int(5)
509array(5) {
510  [0]=>
511  array(2) {
512    [0]=>
513    int(1)
514    [1]=>
515    int(2)
516  }
517  ["f"]=>
518  string(5) "first"
519  ["s"]=>
520  string(6) "second"
521  [1]=>
522  int(1)
523  [2]=>
524  float(2.222)
525}
526int(7)
527array(7) {
528  [0]=>
529  array(2) {
530    [0]=>
531    int(1)
532    [1]=>
533    int(2)
534  }
535  [1]=>
536  string(5) "hello"
537  [2]=>
538  string(5) "world"
539  ["f"]=>
540  string(5) "first"
541  ["s"]=>
542  string(6) "second"
543  [3]=>
544  int(1)
545  [4]=>
546  float(2.222)
547}
548-- Iteration 14 --
549int(5)
550array(5) {
551  [0]=>
552  array(2) {
553    ["color"]=>
554    string(3) "red"
555    ["item"]=>
556    string(3) "pen"
557  }
558  ["f"]=>
559  string(5) "first"
560  ["s"]=>
561  string(6) "second"
562  [1]=>
563  int(1)
564  [2]=>
565  float(2.222)
566}
567int(7)
568array(7) {
569  [0]=>
570  array(2) {
571    ["color"]=>
572    string(3) "red"
573    ["item"]=>
574    string(3) "pen"
575  }
576  [1]=>
577  string(5) "hello"
578  [2]=>
579  string(5) "world"
580  ["f"]=>
581  string(5) "first"
582  ["s"]=>
583  string(6) "second"
584  [3]=>
585  int(1)
586  [4]=>
587  float(2.222)
588}
589-- Iteration 15 --
590int(5)
591array(5) {
592  [0]=>
593  NULL
594  ["f"]=>
595  string(5) "first"
596  ["s"]=>
597  string(6) "second"
598  [1]=>
599  int(1)
600  [2]=>
601  float(2.222)
602}
603int(7)
604array(7) {
605  [0]=>
606  NULL
607  [1]=>
608  string(5) "hello"
609  [2]=>
610  string(5) "world"
611  ["f"]=>
612  string(5) "first"
613  ["s"]=>
614  string(6) "second"
615  [3]=>
616  int(1)
617  [4]=>
618  float(2.222)
619}
620-- Iteration 16 --
621int(5)
622array(5) {
623  [0]=>
624  NULL
625  ["f"]=>
626  string(5) "first"
627  ["s"]=>
628  string(6) "second"
629  [1]=>
630  int(1)
631  [2]=>
632  float(2.222)
633}
634int(7)
635array(7) {
636  [0]=>
637  NULL
638  [1]=>
639  string(5) "hello"
640  [2]=>
641  string(5) "world"
642  ["f"]=>
643  string(5) "first"
644  ["s"]=>
645  string(6) "second"
646  [3]=>
647  int(1)
648  [4]=>
649  float(2.222)
650}
651-- Iteration 17 --
652int(5)
653array(5) {
654  [0]=>
655  bool(true)
656  ["f"]=>
657  string(5) "first"
658  ["s"]=>
659  string(6) "second"
660  [1]=>
661  int(1)
662  [2]=>
663  float(2.222)
664}
665int(7)
666array(7) {
667  [0]=>
668  bool(true)
669  [1]=>
670  string(5) "hello"
671  [2]=>
672  string(5) "world"
673  ["f"]=>
674  string(5) "first"
675  ["s"]=>
676  string(6) "second"
677  [3]=>
678  int(1)
679  [4]=>
680  float(2.222)
681}
682-- Iteration 18 --
683int(5)
684array(5) {
685  [0]=>
686  bool(false)
687  ["f"]=>
688  string(5) "first"
689  ["s"]=>
690  string(6) "second"
691  [1]=>
692  int(1)
693  [2]=>
694  float(2.222)
695}
696int(7)
697array(7) {
698  [0]=>
699  bool(false)
700  [1]=>
701  string(5) "hello"
702  [2]=>
703  string(5) "world"
704  ["f"]=>
705  string(5) "first"
706  ["s"]=>
707  string(6) "second"
708  [3]=>
709  int(1)
710  [4]=>
711  float(2.222)
712}
713-- Iteration 19 --
714int(5)
715array(5) {
716  [0]=>
717  bool(true)
718  ["f"]=>
719  string(5) "first"
720  ["s"]=>
721  string(6) "second"
722  [1]=>
723  int(1)
724  [2]=>
725  float(2.222)
726}
727int(7)
728array(7) {
729  [0]=>
730  bool(true)
731  [1]=>
732  string(5) "hello"
733  [2]=>
734  string(5) "world"
735  ["f"]=>
736  string(5) "first"
737  ["s"]=>
738  string(6) "second"
739  [3]=>
740  int(1)
741  [4]=>
742  float(2.222)
743}
744-- Iteration 20 --
745int(5)
746array(5) {
747  [0]=>
748  bool(false)
749  ["f"]=>
750  string(5) "first"
751  ["s"]=>
752  string(6) "second"
753  [1]=>
754  int(1)
755  [2]=>
756  float(2.222)
757}
758int(7)
759array(7) {
760  [0]=>
761  bool(false)
762  [1]=>
763  string(5) "hello"
764  [2]=>
765  string(5) "world"
766  ["f"]=>
767  string(5) "first"
768  ["s"]=>
769  string(6) "second"
770  [3]=>
771  int(1)
772  [4]=>
773  float(2.222)
774}
775-- Iteration 21 --
776int(5)
777array(5) {
778  [0]=>
779  string(0) ""
780  ["f"]=>
781  string(5) "first"
782  ["s"]=>
783  string(6) "second"
784  [1]=>
785  int(1)
786  [2]=>
787  float(2.222)
788}
789int(7)
790array(7) {
791  [0]=>
792  string(0) ""
793  [1]=>
794  string(5) "hello"
795  [2]=>
796  string(5) "world"
797  ["f"]=>
798  string(5) "first"
799  ["s"]=>
800  string(6) "second"
801  [3]=>
802  int(1)
803  [4]=>
804  float(2.222)
805}
806-- Iteration 22 --
807int(5)
808array(5) {
809  [0]=>
810  string(0) ""
811  ["f"]=>
812  string(5) "first"
813  ["s"]=>
814  string(6) "second"
815  [1]=>
816  int(1)
817  [2]=>
818  float(2.222)
819}
820int(7)
821array(7) {
822  [0]=>
823  string(0) ""
824  [1]=>
825  string(5) "hello"
826  [2]=>
827  string(5) "world"
828  ["f"]=>
829  string(5) "first"
830  ["s"]=>
831  string(6) "second"
832  [3]=>
833  int(1)
834  [4]=>
835  float(2.222)
836}
837-- Iteration 23 --
838int(5)
839array(5) {
840  [0]=>
841  string(6) "string"
842  ["f"]=>
843  string(5) "first"
844  ["s"]=>
845  string(6) "second"
846  [1]=>
847  int(1)
848  [2]=>
849  float(2.222)
850}
851int(7)
852array(7) {
853  [0]=>
854  string(6) "string"
855  [1]=>
856  string(5) "hello"
857  [2]=>
858  string(5) "world"
859  ["f"]=>
860  string(5) "first"
861  ["s"]=>
862  string(6) "second"
863  [3]=>
864  int(1)
865  [4]=>
866  float(2.222)
867}
868-- Iteration 24 --
869int(5)
870array(5) {
871  [0]=>
872  string(6) "string"
873  ["f"]=>
874  string(5) "first"
875  ["s"]=>
876  string(6) "second"
877  [1]=>
878  int(1)
879  [2]=>
880  float(2.222)
881}
882int(7)
883array(7) {
884  [0]=>
885  string(6) "string"
886  [1]=>
887  string(5) "hello"
888  [2]=>
889  string(5) "world"
890  ["f"]=>
891  string(5) "first"
892  ["s"]=>
893  string(6) "second"
894  [3]=>
895  int(1)
896  [4]=>
897  float(2.222)
898}
899-- Iteration 25 --
900int(5)
901array(5) {
902  [0]=>
903  string(11) "hello world"
904  ["f"]=>
905  string(5) "first"
906  ["s"]=>
907  string(6) "second"
908  [1]=>
909  int(1)
910  [2]=>
911  float(2.222)
912}
913int(7)
914array(7) {
915  [0]=>
916  string(11) "hello world"
917  [1]=>
918  string(5) "hello"
919  [2]=>
920  string(5) "world"
921  ["f"]=>
922  string(5) "first"
923  ["s"]=>
924  string(6) "second"
925  [3]=>
926  int(1)
927  [4]=>
928  float(2.222)
929}
930-- Iteration 26 --
931int(5)
932array(5) {
933  [0]=>
934  object(classA)#%d (0) {
935  }
936  ["f"]=>
937  string(5) "first"
938  ["s"]=>
939  string(6) "second"
940  [1]=>
941  int(1)
942  [2]=>
943  float(2.222)
944}
945int(7)
946array(7) {
947  [0]=>
948  object(classA)#%d (0) {
949  }
950  [1]=>
951  string(5) "hello"
952  [2]=>
953  string(5) "world"
954  ["f"]=>
955  string(5) "first"
956  ["s"]=>
957  string(6) "second"
958  [3]=>
959  int(1)
960  [4]=>
961  float(2.222)
962}
963-- Iteration 27 --
964int(5)
965array(5) {
966  [0]=>
967  NULL
968  ["f"]=>
969  string(5) "first"
970  ["s"]=>
971  string(6) "second"
972  [1]=>
973  int(1)
974  [2]=>
975  float(2.222)
976}
977int(7)
978array(7) {
979  [0]=>
980  NULL
981  [1]=>
982  string(5) "hello"
983  [2]=>
984  string(5) "world"
985  ["f"]=>
986  string(5) "first"
987  ["s"]=>
988  string(6) "second"
989  [3]=>
990  int(1)
991  [4]=>
992  float(2.222)
993}
994-- Iteration 28 --
995int(5)
996array(5) {
997  [0]=>
998  NULL
999  ["f"]=>
1000  string(5) "first"
1001  ["s"]=>
1002  string(6) "second"
1003  [1]=>
1004  int(1)
1005  [2]=>
1006  float(2.222)
1007}
1008int(7)
1009array(7) {
1010  [0]=>
1011  NULL
1012  [1]=>
1013  string(5) "hello"
1014  [2]=>
1015  string(5) "world"
1016  ["f"]=>
1017  string(5) "first"
1018  ["s"]=>
1019  string(6) "second"
1020  [3]=>
1021  int(1)
1022  [4]=>
1023  float(2.222)
1024}
1025-- Iteration 29 --
1026int(5)
1027array(5) {
1028  [0]=>
1029  resource(%d) of type (stream)
1030  ["f"]=>
1031  string(5) "first"
1032  ["s"]=>
1033  string(6) "second"
1034  [1]=>
1035  int(1)
1036  [2]=>
1037  float(2.222)
1038}
1039int(7)
1040array(7) {
1041  [0]=>
1042  resource(%d) of type (stream)
1043  [1]=>
1044  string(5) "hello"
1045  [2]=>
1046  string(5) "world"
1047  ["f"]=>
1048  string(5) "first"
1049  ["s"]=>
1050  string(6) "second"
1051  [3]=>
1052  int(1)
1053  [4]=>
1054  float(2.222)
1055}
1056Done
1057