/hphp/test/slow/array_object/uasort.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
- <?php
- // Comparison function
- function cmp($a, $b) {
- if ($a == $b) {
- return 0;
- }
- return ($a < $b) ? -1 : 1;
- }
- // Array to be sorted
- $array = array(
- 'a' => 4,
- 'b' => 8,
- 'c' => -1,
- 'd' => -9,
- 'e' => 2,
- 'f' => 5,
- 'g' => 3,
- 'h' => -4,
- );
- $arrayObject = new ArrayObject($array);
- print_r($arrayObject);
- // Sort and print the resulting array
- $arrayObject->uasort('cmp');
- print_r($arrayObject);