3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Zillow { private static $instance = null; public static function get_instance() { if ( null == self::$instance ) { self::$instance = new self; } return self::$instance; } // end get_instance; private function __construct() { } // end constructor public static function sort($data=array()) { array_multisort( array_column($data, 'rent'), SORT_ASC, SORT_NUMERIC, array_column($data, 'street'), SORT_ASC, SORT_NATURAL, array_column($data, 'unit'), SORT_DESC, SORT_REGULAR, $data ); return $data; } // end array_orderby } // end class // Sample array() $data = array(); $data[] = array('id' => 1, 'number' => '130', 'street' => 'Battery St', 'unit' => '1', 'rent' => 1200); $data[] = array('id' => 1, 'number' => '130', 'street' => 'Battery St', 'unit' => '3', 'rent' => 1800); $data[] = array('id' => 1, 'number' => '1049', 'street' => 'Leavenworth St', 'unit' => '11', 'rent' => 800); $data[] = array('id' => 1, 'number' => '130', 'street' => 'Battery St', 'unit' => '10', 'rent' => 3400); $data[] = array('id' => 1, 'number' => '1059', 'street' => 'Leavenworth St', 'unit' => '10', 'rent' => 1450); $data[] = array('id' => 1, 'number' => '130', 'street' => 'Battery St', 'unit' => '5', 'rent' => 1000); $zillow = Zillow::get_instance(); $printed_data = $zillow->sort($data); echo '<pre>'; var_dump($printed_data); echo '</pre>';
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.0
<pre>array(6) { [0]=> array(5) { ["id"]=> int(1) ["number"]=> string(4) "1049" ["street"]=> string(14) "Leavenworth St" ["unit"]=> string(2) "11" ["rent"]=> int(800) } [1]=> array(5) { ["id"]=> int(1) ["number"]=> string(3) "130" ["street"]=> string(10) "Battery St" ["unit"]=> string(1) "5" ["rent"]=> int(1000) } [2]=> array(5) { ["id"]=> int(1) ["number"]=> string(3) "130" ["street"]=> string(10) "Battery St" ["unit"]=> string(1) "1" ["rent"]=> int(1200) } [3]=> array(5) { ["id"]=> int(1) ["number"]=> string(4) "1059" ["street"]=> string(14) "Leavenworth St" ["unit"]=> string(2) "10" ["rent"]=> int(1450) } [4]=> array(5) { ["id"]=> int(1) ["number"]=> string(3) "130" ["street"]=> string(10) "Battery St" ["unit"]=> string(1) "3" ["rent"]=> int(1800) } [5]=> array(5) { ["id"]=> int(1) ["number"]=> string(3) "130" ["street"]=> string(10) "Battery St" ["unit"]=> string(2) "10" ["rent"]=> int(3400) } } </pre>