<?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 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
- <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>
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 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>
preferences:
159.03 ms | 405 KiB | 188 Q