1--TEST--
2Test array_splice() function : usage variations - lengths and offsets
3--FILE--
4<?php
5/*
6 * proto array array_splice(array input, int offset [, int length [, array replacement]])
7 * Function is implemented in ext/standard/array.c
8*/
9
10echo "*** array_splice() function : usage variations - lengths and offsets\n";
11
12
13function test_splice ($offset, $length)
14{
15	echo "  - No replacement\n";
16	$input_array=array(0,1,2,3,4,5);
17	var_dump (array_splice ($input_array,$offset,$length));
18	var_dump ($input_array);
19    echo "  - With replacement\n";
20    $input_array=array(0,1,2,3,4,5);
21    var_dump (array_splice ($input_array,$offset,$length,array ("A","B","C")));
22	var_dump ($input_array);
23}
24
25echo "absolute offset - absolute length - cut from beginning\n";
26test_splice (0,2);
27echo "absolute offset - absolute length - cut from middle\n";
28test_splice (2,2);
29echo "absolute offset - absolute length - cut from end\n";
30test_splice (4,2);
31echo "absolute offset - absolute length - attempt to cut past end\n";
32test_splice (4,4);
33echo "absolute offset - absolute length - cut everything\n";
34test_splice (0,7);
35echo "absolute offset - absolute length - cut nothing\n";
36test_splice (3,0);
37
38echo "absolute offset - relative length - cut from beginning\n";
39test_splice (0,-4);
40
41echo "absolute offset - relative length - cut from middle\n";
42test_splice (2,-2);
43
44echo "absolute offset - relative length - attempt to cut form before beginning \n";
45test_splice (0,-7);
46
47echo "absolute offset - relative length - cut nothing\n";
48test_splice (2,-7);
49
50echo "relative offset - absolute length - cut from beginning\n";
51test_splice (-6,2);
52
53echo "relative offset - absolute length - cut from middle\n";
54test_splice (-4,2);
55echo "relative offset - absolute length - cut from end\n";
56test_splice (-2,2);
57echo "relative offset - absolute length - attempt to cut past end\n";
58test_splice (-2,4);
59echo "relative offset - absolute length - cut everything\n";
60test_splice (-6,6);
61echo "relative offset - absolute length - cut nothing\n";
62test_splice (-6,0);
63
64echo "relative offset - relative length - cut from beginning\n";
65test_splice (-6,-4);
66
67echo "relative offset - relative length - cut from middle\n";
68test_splice (-4,-2);
69
70echo "relative offset - relative length - cut nothing\n";
71test_splice (-4,-7);
72echo "Done\n";
73?>
74--EXPECT--
75*** array_splice() function : usage variations - lengths and offsets
76absolute offset - absolute length - cut from beginning
77  - No replacement
78array(2) {
79  [0]=>
80  int(0)
81  [1]=>
82  int(1)
83}
84array(4) {
85  [0]=>
86  int(2)
87  [1]=>
88  int(3)
89  [2]=>
90  int(4)
91  [3]=>
92  int(5)
93}
94  - With replacement
95array(2) {
96  [0]=>
97  int(0)
98  [1]=>
99  int(1)
100}
101array(7) {
102  [0]=>
103  string(1) "A"
104  [1]=>
105  string(1) "B"
106  [2]=>
107  string(1) "C"
108  [3]=>
109  int(2)
110  [4]=>
111  int(3)
112  [5]=>
113  int(4)
114  [6]=>
115  int(5)
116}
117absolute offset - absolute length - cut from middle
118  - No replacement
119array(2) {
120  [0]=>
121  int(2)
122  [1]=>
123  int(3)
124}
125array(4) {
126  [0]=>
127  int(0)
128  [1]=>
129  int(1)
130  [2]=>
131  int(4)
132  [3]=>
133  int(5)
134}
135  - With replacement
136array(2) {
137  [0]=>
138  int(2)
139  [1]=>
140  int(3)
141}
142array(7) {
143  [0]=>
144  int(0)
145  [1]=>
146  int(1)
147  [2]=>
148  string(1) "A"
149  [3]=>
150  string(1) "B"
151  [4]=>
152  string(1) "C"
153  [5]=>
154  int(4)
155  [6]=>
156  int(5)
157}
158absolute offset - absolute length - cut from end
159  - No replacement
160array(2) {
161  [0]=>
162  int(4)
163  [1]=>
164  int(5)
165}
166array(4) {
167  [0]=>
168  int(0)
169  [1]=>
170  int(1)
171  [2]=>
172  int(2)
173  [3]=>
174  int(3)
175}
176  - With replacement
177array(2) {
178  [0]=>
179  int(4)
180  [1]=>
181  int(5)
182}
183array(7) {
184  [0]=>
185  int(0)
186  [1]=>
187  int(1)
188  [2]=>
189  int(2)
190  [3]=>
191  int(3)
192  [4]=>
193  string(1) "A"
194  [5]=>
195  string(1) "B"
196  [6]=>
197  string(1) "C"
198}
199absolute offset - absolute length - attempt to cut past end
200  - No replacement
201array(2) {
202  [0]=>
203  int(4)
204  [1]=>
205  int(5)
206}
207array(4) {
208  [0]=>
209  int(0)
210  [1]=>
211  int(1)
212  [2]=>
213  int(2)
214  [3]=>
215  int(3)
216}
217  - With replacement
218array(2) {
219  [0]=>
220  int(4)
221  [1]=>
222  int(5)
223}
224array(7) {
225  [0]=>
226  int(0)
227  [1]=>
228  int(1)
229  [2]=>
230  int(2)
231  [3]=>
232  int(3)
233  [4]=>
234  string(1) "A"
235  [5]=>
236  string(1) "B"
237  [6]=>
238  string(1) "C"
239}
240absolute offset - absolute length - cut everything
241  - No replacement
242array(6) {
243  [0]=>
244  int(0)
245  [1]=>
246  int(1)
247  [2]=>
248  int(2)
249  [3]=>
250  int(3)
251  [4]=>
252  int(4)
253  [5]=>
254  int(5)
255}
256array(0) {
257}
258  - With replacement
259array(6) {
260  [0]=>
261  int(0)
262  [1]=>
263  int(1)
264  [2]=>
265  int(2)
266  [3]=>
267  int(3)
268  [4]=>
269  int(4)
270  [5]=>
271  int(5)
272}
273array(3) {
274  [0]=>
275  string(1) "A"
276  [1]=>
277  string(1) "B"
278  [2]=>
279  string(1) "C"
280}
281absolute offset - absolute length - cut nothing
282  - No replacement
283array(0) {
284}
285array(6) {
286  [0]=>
287  int(0)
288  [1]=>
289  int(1)
290  [2]=>
291  int(2)
292  [3]=>
293  int(3)
294  [4]=>
295  int(4)
296  [5]=>
297  int(5)
298}
299  - With replacement
300array(0) {
301}
302array(9) {
303  [0]=>
304  int(0)
305  [1]=>
306  int(1)
307  [2]=>
308  int(2)
309  [3]=>
310  string(1) "A"
311  [4]=>
312  string(1) "B"
313  [5]=>
314  string(1) "C"
315  [6]=>
316  int(3)
317  [7]=>
318  int(4)
319  [8]=>
320  int(5)
321}
322absolute offset - relative length - cut from beginning
323  - No replacement
324array(2) {
325  [0]=>
326  int(0)
327  [1]=>
328  int(1)
329}
330array(4) {
331  [0]=>
332  int(2)
333  [1]=>
334  int(3)
335  [2]=>
336  int(4)
337  [3]=>
338  int(5)
339}
340  - With replacement
341array(2) {
342  [0]=>
343  int(0)
344  [1]=>
345  int(1)
346}
347array(7) {
348  [0]=>
349  string(1) "A"
350  [1]=>
351  string(1) "B"
352  [2]=>
353  string(1) "C"
354  [3]=>
355  int(2)
356  [4]=>
357  int(3)
358  [5]=>
359  int(4)
360  [6]=>
361  int(5)
362}
363absolute offset - relative length - cut from middle
364  - No replacement
365array(2) {
366  [0]=>
367  int(2)
368  [1]=>
369  int(3)
370}
371array(4) {
372  [0]=>
373  int(0)
374  [1]=>
375  int(1)
376  [2]=>
377  int(4)
378  [3]=>
379  int(5)
380}
381  - With replacement
382array(2) {
383  [0]=>
384  int(2)
385  [1]=>
386  int(3)
387}
388array(7) {
389  [0]=>
390  int(0)
391  [1]=>
392  int(1)
393  [2]=>
394  string(1) "A"
395  [3]=>
396  string(1) "B"
397  [4]=>
398  string(1) "C"
399  [5]=>
400  int(4)
401  [6]=>
402  int(5)
403}
404absolute offset - relative length - attempt to cut form before beginning
405  - No replacement
406array(0) {
407}
408array(6) {
409  [0]=>
410  int(0)
411  [1]=>
412  int(1)
413  [2]=>
414  int(2)
415  [3]=>
416  int(3)
417  [4]=>
418  int(4)
419  [5]=>
420  int(5)
421}
422  - With replacement
423array(0) {
424}
425array(9) {
426  [0]=>
427  string(1) "A"
428  [1]=>
429  string(1) "B"
430  [2]=>
431  string(1) "C"
432  [3]=>
433  int(0)
434  [4]=>
435  int(1)
436  [5]=>
437  int(2)
438  [6]=>
439  int(3)
440  [7]=>
441  int(4)
442  [8]=>
443  int(5)
444}
445absolute offset - relative length - cut nothing
446  - No replacement
447array(0) {
448}
449array(6) {
450  [0]=>
451  int(0)
452  [1]=>
453  int(1)
454  [2]=>
455  int(2)
456  [3]=>
457  int(3)
458  [4]=>
459  int(4)
460  [5]=>
461  int(5)
462}
463  - With replacement
464array(0) {
465}
466array(9) {
467  [0]=>
468  int(0)
469  [1]=>
470  int(1)
471  [2]=>
472  string(1) "A"
473  [3]=>
474  string(1) "B"
475  [4]=>
476  string(1) "C"
477  [5]=>
478  int(2)
479  [6]=>
480  int(3)
481  [7]=>
482  int(4)
483  [8]=>
484  int(5)
485}
486relative offset - absolute length - cut from beginning
487  - No replacement
488array(2) {
489  [0]=>
490  int(0)
491  [1]=>
492  int(1)
493}
494array(4) {
495  [0]=>
496  int(2)
497  [1]=>
498  int(3)
499  [2]=>
500  int(4)
501  [3]=>
502  int(5)
503}
504  - With replacement
505array(2) {
506  [0]=>
507  int(0)
508  [1]=>
509  int(1)
510}
511array(7) {
512  [0]=>
513  string(1) "A"
514  [1]=>
515  string(1) "B"
516  [2]=>
517  string(1) "C"
518  [3]=>
519  int(2)
520  [4]=>
521  int(3)
522  [5]=>
523  int(4)
524  [6]=>
525  int(5)
526}
527relative offset - absolute length - cut from middle
528  - No replacement
529array(2) {
530  [0]=>
531  int(2)
532  [1]=>
533  int(3)
534}
535array(4) {
536  [0]=>
537  int(0)
538  [1]=>
539  int(1)
540  [2]=>
541  int(4)
542  [3]=>
543  int(5)
544}
545  - With replacement
546array(2) {
547  [0]=>
548  int(2)
549  [1]=>
550  int(3)
551}
552array(7) {
553  [0]=>
554  int(0)
555  [1]=>
556  int(1)
557  [2]=>
558  string(1) "A"
559  [3]=>
560  string(1) "B"
561  [4]=>
562  string(1) "C"
563  [5]=>
564  int(4)
565  [6]=>
566  int(5)
567}
568relative offset - absolute length - cut from end
569  - No replacement
570array(2) {
571  [0]=>
572  int(4)
573  [1]=>
574  int(5)
575}
576array(4) {
577  [0]=>
578  int(0)
579  [1]=>
580  int(1)
581  [2]=>
582  int(2)
583  [3]=>
584  int(3)
585}
586  - With replacement
587array(2) {
588  [0]=>
589  int(4)
590  [1]=>
591  int(5)
592}
593array(7) {
594  [0]=>
595  int(0)
596  [1]=>
597  int(1)
598  [2]=>
599  int(2)
600  [3]=>
601  int(3)
602  [4]=>
603  string(1) "A"
604  [5]=>
605  string(1) "B"
606  [6]=>
607  string(1) "C"
608}
609relative offset - absolute length - attempt to cut past end
610  - No replacement
611array(2) {
612  [0]=>
613  int(4)
614  [1]=>
615  int(5)
616}
617array(4) {
618  [0]=>
619  int(0)
620  [1]=>
621  int(1)
622  [2]=>
623  int(2)
624  [3]=>
625  int(3)
626}
627  - With replacement
628array(2) {
629  [0]=>
630  int(4)
631  [1]=>
632  int(5)
633}
634array(7) {
635  [0]=>
636  int(0)
637  [1]=>
638  int(1)
639  [2]=>
640  int(2)
641  [3]=>
642  int(3)
643  [4]=>
644  string(1) "A"
645  [5]=>
646  string(1) "B"
647  [6]=>
648  string(1) "C"
649}
650relative offset - absolute length - cut everything
651  - No replacement
652array(6) {
653  [0]=>
654  int(0)
655  [1]=>
656  int(1)
657  [2]=>
658  int(2)
659  [3]=>
660  int(3)
661  [4]=>
662  int(4)
663  [5]=>
664  int(5)
665}
666array(0) {
667}
668  - With replacement
669array(6) {
670  [0]=>
671  int(0)
672  [1]=>
673  int(1)
674  [2]=>
675  int(2)
676  [3]=>
677  int(3)
678  [4]=>
679  int(4)
680  [5]=>
681  int(5)
682}
683array(3) {
684  [0]=>
685  string(1) "A"
686  [1]=>
687  string(1) "B"
688  [2]=>
689  string(1) "C"
690}
691relative offset - absolute length - cut nothing
692  - No replacement
693array(0) {
694}
695array(6) {
696  [0]=>
697  int(0)
698  [1]=>
699  int(1)
700  [2]=>
701  int(2)
702  [3]=>
703  int(3)
704  [4]=>
705  int(4)
706  [5]=>
707  int(5)
708}
709  - With replacement
710array(0) {
711}
712array(9) {
713  [0]=>
714  string(1) "A"
715  [1]=>
716  string(1) "B"
717  [2]=>
718  string(1) "C"
719  [3]=>
720  int(0)
721  [4]=>
722  int(1)
723  [5]=>
724  int(2)
725  [6]=>
726  int(3)
727  [7]=>
728  int(4)
729  [8]=>
730  int(5)
731}
732relative offset - relative length - cut from beginning
733  - No replacement
734array(2) {
735  [0]=>
736  int(0)
737  [1]=>
738  int(1)
739}
740array(4) {
741  [0]=>
742  int(2)
743  [1]=>
744  int(3)
745  [2]=>
746  int(4)
747  [3]=>
748  int(5)
749}
750  - With replacement
751array(2) {
752  [0]=>
753  int(0)
754  [1]=>
755  int(1)
756}
757array(7) {
758  [0]=>
759  string(1) "A"
760  [1]=>
761  string(1) "B"
762  [2]=>
763  string(1) "C"
764  [3]=>
765  int(2)
766  [4]=>
767  int(3)
768  [5]=>
769  int(4)
770  [6]=>
771  int(5)
772}
773relative offset - relative length - cut from middle
774  - No replacement
775array(2) {
776  [0]=>
777  int(2)
778  [1]=>
779  int(3)
780}
781array(4) {
782  [0]=>
783  int(0)
784  [1]=>
785  int(1)
786  [2]=>
787  int(4)
788  [3]=>
789  int(5)
790}
791  - With replacement
792array(2) {
793  [0]=>
794  int(2)
795  [1]=>
796  int(3)
797}
798array(7) {
799  [0]=>
800  int(0)
801  [1]=>
802  int(1)
803  [2]=>
804  string(1) "A"
805  [3]=>
806  string(1) "B"
807  [4]=>
808  string(1) "C"
809  [5]=>
810  int(4)
811  [6]=>
812  int(5)
813}
814relative offset - relative length - cut nothing
815  - No replacement
816array(0) {
817}
818array(6) {
819  [0]=>
820  int(0)
821  [1]=>
822  int(1)
823  [2]=>
824  int(2)
825  [3]=>
826  int(3)
827  [4]=>
828  int(4)
829  [5]=>
830  int(5)
831}
832  - With replacement
833array(0) {
834}
835array(9) {
836  [0]=>
837  int(0)
838  [1]=>
839  int(1)
840  [2]=>
841  string(1) "A"
842  [3]=>
843  string(1) "B"
844  [4]=>
845  string(1) "C"
846  [5]=>
847  int(2)
848  [6]=>
849  int(3)
850  [7]=>
851  int(4)
852  [8]=>
853  int(5)
854}
855Done
856