PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/good/ext/standard/tests/array/array_reverse_variation6.php

http://github.com/facebook/hiphop-php
PHP | 42 lines | 18 code | 8 blank | 16 comment | 0 complexity | 20d676b576d42fcba82d37bb20019fa2 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh
  2. /* Prototype : array array_reverse(array $array [, bool $preserve_keys])
  3. * Description: Return input as a new array with the order of the entries reversed
  4. * Source code: ext/standard/array.c
  5. */
  6. /*
  7. * testing the functionality of array_reverse() by giving 2-D arrays for $array argument
  8. */
  9. <<__EntryPoint>> function main(): void {
  10. echo "*** Testing array_reverse() : usage variations ***\n";
  11. // Initializing the 2-d arrays
  12. $two_dimensional_array = varray[
  13. // associative array
  14. darray['color' => 'red', 'item' => 'pen', 'place' => 'LA'],
  15. // numeric array
  16. varray[1, 2, 3, 4, 5],
  17. // combination of numeric and associative arrays
  18. darray['a' => 'green', 0 => 'red', 1 => 'brown', 2 => 33, 3 => 88, 4 => 'orange', 'item' => 'ball']
  19. ];
  20. // calling array_reverse() with various types of 2-d arrays
  21. // with default arguments
  22. echo "-- with default argument --\n";
  23. var_dump( array_reverse($two_dimensional_array) ); // whole array
  24. var_dump( array_reverse($two_dimensional_array[1]) ); // sub array
  25. // with $preserve_keys argument
  26. echo "-- with all possible arguments --\n";
  27. // whole array
  28. var_dump( array_reverse($two_dimensional_array, true) );
  29. var_dump( array_reverse($two_dimensional_array, false) );
  30. // sub array
  31. var_dump( array_reverse($two_dimensional_array[1], true) );
  32. var_dump( array_reverse($two_dimensional_array[1], false) );
  33. echo "Done";
  34. }