3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $tickets = array( array( 'id' => 13, 'pid' => 1, 'owner' => 'jachim', 'time' => '2009-09-25 10:39:42.011612', 'project' => 'jachim.be', 'title' => 'Some random ticket' ), array( 'id' => 31, 'pid' => 2, 'owner' => 'jachim', 'time' => '2009-09-24 14:38:47.945020', 'project' => 'joggink.be', 'title' => 'Some other random ticket' ), array( 'id' => 22, 'pid' => 3, 'owner' => 'root', 'time' => '2009-09-24 10:58:02.904198', 'project' => 'joggink.be', 'title' => 'A specific ticket' ), array( 'id' => 18, 'pid' => 4, 'owner' => 'root', 'time' => '2009-09-24 10:58:02.904198', 'project' => 'joggink.be', 'title' => 'A specific ticket' ) ); function msort($array, $key, $sort_flags = SORT_REGULAR) { if (is_array($array) && count($array) > 0) { if (!empty($key)) { $mapping = array(); foreach ($array as $k => $v) { $sort_key = ''; if (!is_array($key)) { $sort_key = $v[$key]; } else { // @TODO This should be fixed, now it will be sorted as string foreach ($key as $key_key) { $sort_key .= $v[$key_key]; } $sort_flags = SORT_STRING; } $mapping[$k] = $sort_key; } asort($mapping, $sort_flags); $sorted = array(); foreach ($mapping as $k => $v) { $sorted[] = $array[$k]; } return $sorted; } } return $array; } //var_dump($tickets); $tickets = msort($tickets, array('pid','id')); var_dump($tickets); ?>
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(4) { [0]=> array(6) { ["id"]=> int(13) ["pid"]=> int(1) ["owner"]=> string(6) "jachim" ["time"]=> string(26) "2009-09-25 10:39:42.011612" ["project"]=> string(9) "jachim.be" ["title"]=> string(18) "Some random ticket" } [1]=> array(6) { ["id"]=> int(31) ["pid"]=> int(2) ["owner"]=> string(6) "jachim" ["time"]=> string(26) "2009-09-24 14:38:47.945020" ["project"]=> string(10) "joggink.be" ["title"]=> string(24) "Some other random ticket" } [2]=> array(6) { ["id"]=> int(22) ["pid"]=> int(3) ["owner"]=> string(4) "root" ["time"]=> string(26) "2009-09-24 10:58:02.904198" ["project"]=> string(10) "joggink.be" ["title"]=> string(17) "A specific ticket" } [3]=> array(6) { ["id"]=> int(18) ["pid"]=> int(4) ["owner"]=> string(4) "root" ["time"]=> string(26) "2009-09-24 10:58:02.904198" ["project"]=> string(10) "joggink.be" ["title"]=> string(17) "A specific ticket" } }