आप भी कई मूल्यों के लिए बहुआयामी सरणी को सॉर्ट कर सकते हैं जैसे कि
$arr = [
[
"name"=> "Sally",
"nick_name"=> "sal",
"availability"=> "0",
"is_fav"=> "0"
],
[
"name"=> "David",
"nick_name"=> "dav07",
"availability"=> "0",
"is_fav"=> "1"
],
[
"name"=> "Zen",
"nick_name"=> "zen",
"availability"=> "1",
"is_fav"=> "0"
],
[
"name"=> "Jackson",
"nick_name"=> "jack",
"availability"=> "1",
"is_fav"=> "1"
],
[
"name"=> "Rohit",
"nick_name"=> "rod",
"availability"=> "0",
"is_fav"=> "0"
],
];
साथ में
usort($arr,function($a,$b){
$c = $b['is_fav'] - $a['is_fav'];
$c .= $b['availability'] - $a['availability'];
$c .= strcmp($a['nick_name'],$b['nick_name']);
return $c;
});
उत्पादन का उपयोग print_r($arr)
:
Array
(
[0] => Array
(
[name] => Jackson
[nick_name] => jack
[availability] => 1
[is_fav] => 1
)
[1] => Array
(
[name] => David
[nick_name] => dav07
[availability] => 0
[is_fav] => 1
)
[2] => Array
(
[name] => Zen
[nick_name] => zen
[availability] => 1
[is_fav] => 0
)
[3] => Array
(
[name] => Rohit
[nick_name] => rod
[availability] => 0
[is_fav] => 0
)
[4] => Array
(
[name] => Sally
[nick_name] => sal
[availability] => 0
[is_fav] => 0
)
)
PS) स्ट्रिंग्स की तुलना करने के लिए strcmp का उपयोग करना एक अच्छा विकल्प होगा।