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 33--EXPECTF-- 34*** Testing array_slice() : usage variations *** 35 36-- Array of referenced variables ($preserve_keys = default) -- 37array(2) { 38 [0]=> 39 &string(3) "two" 40 [1]=> 41 &string(5) "three" 42} 43-- Change $val2 ($preserve_keys = TRUE) -- 44array(2) { 45 [2]=> 46 &string(12) "hello, world" 47 [1]=> 48 &string(5) "three" 49} 50Done 51