我需要搜索这个数组:
cars -
[0] -make : Ford
-model: Escort
-year: 1991
[1] -make: Honda
-model: Civic
-year: 1996
[2] -make: Vauxhall
-model: Astra
-year: 1972
如果(例如)模型是“Civic”,则将该“汽车”放在位置 0。
所以结束数组会是这样的:
cars -
[0] -make: Honda
-model: Civic
-year: 1996
[1] -make : Ford
-model: Escort
-year: 1991
[2] -make: Vauxhall
-model: Astra
-year: 1972
我尝试了一些 usort 变体:
function typeSort($a, $b)
{
if ($a['model'] == 'Civic' )
{
return 0;
}
return ($a['model'] < $b['model']) ? -1 : 1;
}
但这只是回归1