key_basic.phpt 902 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. --TEST--
  2. Test key() function : basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype : mixed key(array $array_arg)
  6. * Description: Return the key of the element currently pointed to by the internal array pointer
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Test basic functionality of key()
  11. */
  12. echo "*** Testing key() : basic functionality ***\n";
  13. $array = array ('zero', 99 => 'one', 'two', 'three' => 3);
  14. echo "\n-- Initial Position: --\n";
  15. var_dump(key($array));
  16. echo "\n-- Next Position: --\n";
  17. next($array);
  18. var_dump(key($array));
  19. echo "\n-- End Position: --\n";
  20. end($array);
  21. var_dump(key($array));
  22. echo "\n-- Past end of the array --\n";
  23. next($array);
  24. var_dump(key($array));
  25. ?>
  26. ===DONE===
  27. --EXPECTF--
  28. *** Testing key() : basic functionality ***
  29. -- Initial Position: --
  30. int(0)
  31. -- Next Position: --
  32. int(99)
  33. -- End Position: --
  34. string(5) "three"
  35. -- Past end of the array --
  36. NULL
  37. ===DONE===