También puede ordenar la matriz multidimensional para múltiples valores como
$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"
],
];
con
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;
});
Salida usando 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) usar strcmp sería una buena opción para comparar las cadenas.