1--TEST-- 2Test array_slice() function : usage variations - referenced variables 3--INI-- 4allow_call_time_pass_reference=on 5--FILE-- 6<?php 7/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) 8 * Description: Returns elements specified by offset and length 9 * Source code: ext/standard/array.c 10 */ 11 12/* 13 * Test array_slice() when: 14 * 1. Passed an array of referenced variables 15 * 2. $input argument is passed by reference 16 */ 17 18echo "*** Testing array_slice() : usage variations ***\n"; 19 20$val1 = 'one'; 21$val2 = 'two'; 22$val3 = 'three'; 23 24echo "\n-- Array of referenced variables (\$preserve_keys = default) --\n"; 25$input = array(3 => &$val1, 2 => &$val2, 1 => &$val3); 26var_dump(array_slice($input, 1, 2)); 27 28echo "-- Change \$val2 (\$preserve_keys = TRUE) --\n"; 29$val2 = 'hello, world'; 30var_dump(array_slice($input, 1, 2, true)); 31 32echo "\n-- Pass array by reference --\n"; 33$new_input = array (1, 2, 3); 34var_dump(array_slice(&$new_input, 1)); 35echo "-- Check passed array: --\n"; 36var_dump($new_input); 37 38echo "Done"; 39?> 40 41--EXPECTF-- 42*** Testing array_slice() : usage variations *** 43 44-- Array of referenced variables ($preserve_keys = default) -- 45array(2) { 46 [0]=> 47 &string(3) "two" 48 [1]=> 49 &string(5) "three" 50} 51-- Change $val2 ($preserve_keys = TRUE) -- 52array(2) { 53 [2]=> 54 &string(12) "hello, world" 55 [1]=> 56 &string(5) "three" 57} 58 59-- Pass array by reference -- 60array(2) { 61 [0]=> 62 int(2) 63 [1]=> 64 int(3) 65} 66-- Check passed array: -- 67array(3) { 68 [0]=> 69 int(1) 70 [1]=> 71 int(2) 72 [2]=> 73 int(3) 74} 75Done 76