PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/slow/array_object/uasort.php

http://github.com/facebook/hiphop-php
PHP | 27 lines | 21 code | 3 blank | 3 comment | 2 complexity | 9b579fb73bf5e30dd25b79abf73f4962 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. <?php
  2. // Comparison function
  3. function cmp($a, $b) {
  4. if ($a == $b) {
  5. return 0;
  6. }
  7. return ($a < $b) ? -1 : 1;
  8. }
  9. // Array to be sorted
  10. $array = array(
  11. 'a' => 4,
  12. 'b' => 8,
  13. 'c' => -1,
  14. 'd' => -9,
  15. 'e' => 2,
  16. 'f' => 5,
  17. 'g' => 3,
  18. 'h' => -4,
  19. );
  20. $arrayObject = new ArrayObject($array);
  21. print_r($arrayObject);
  22. // Sort and print the resulting array
  23. $arrayObject->uasort('cmp');
  24. print_r($arrayObject);