/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

  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);