array_slice_variation10.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. --TEST--
  2. Test array_slice() function : usage variations - position of internal array pointer
  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. * Check position of internal array pointer after calling array_slice()
  11. */
  12. echo "*** Testing array_slice() : usage variations ***\n";
  13. $input = array ('one' => 'un', 'two' => 'deux', 23 => 'twenty-three', 'zero');
  14. echo "\n-- Call array_slice() --\n";
  15. var_dump($result = array_slice($input, 2));
  16. echo "-- Position of Internal Pointer in Result: --\n";
  17. echo key($result) . " => " . current($result) . "\n";
  18. echo "\n-- Position of Internal Pointer in Original Array: --\n";
  19. echo key($input) . " => " . current ($input) . "\n";
  20. echo "Done";
  21. ?>
  22. --EXPECTF--
  23. *** Testing array_slice() : usage variations ***
  24. -- Call array_slice() --
  25. array(2) {
  26. [0]=>
  27. string(12) "twenty-three"
  28. [1]=>
  29. string(4) "zero"
  30. }
  31. -- Position of Internal Pointer in Result: --
  32. 0 => twenty-three
  33. -- Position of Internal Pointer in Original Array: --
  34. one => un
  35. Done