1--TEST-- 2Test array_slice() function : usage variations - referenced variables 3--FILE-- 4<?php 5/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) 6 * Description: Returns elements specified by offset and length 7 * Source code: ext/standard/array.c 8 */ 9 10/* 11 * Test array_slice() when: 12 * 1. Passed an array of referenced variables 13 * 2. $input argument is passed by reference 14 */ 15 16echo "*** Testing array_slice() : usage variations ***\n"; 17 18$val1 = 'one'; 19$val2 = 'two'; 20$val3 = 'three'; 21 22echo "\n-- Array of referenced variables (\$preserve_keys = default) --\n"; 23$input = array(3 => &$val1, 2 => &$val2, 1 => &$val3); 24var_dump(array_slice($input, 1, 2)); 25 26echo "-- Change \$val2 (\$preserve_keys = TRUE) --\n"; 27$val2 = 'hello, world'; 28var_dump(array_slice($input, 1, 2, true)); 29 30echo "Done"; 31?> 32--EXPECT-- 33*** Testing array_slice() : usage variations *** 34 35-- Array of referenced variables ($preserve_keys = default) -- 36array(2) { 37 [0]=> 38 &string(3) "two" 39 [1]=> 40 &string(5) "three" 41} 42-- Change $val2 ($preserve_keys = TRUE) -- 43array(2) { 44 [2]=> 45 &string(12) "hello, world" 46 [1]=> 47 &string(5) "three" 48} 49Done 50