PHP search multidimensional array for value, then place that element at start of array
- by BobFlemming
I need to search this array:
cars -
[0] -make : Ford
-model: Escort
-year: 1991
[1] -make: Honda
-model: Civic
-year: 1996
[2] -make: Vauxhall
-model: Astra
-year: 1972
And if (for example) the model is "Civic" , place that 'car' at position 0.
So the end array would be like:
cars -
[0] -make: Honda
-model: Civic
-year: 1996
[1] -make : Ford
-model: Escort
-year: 1991
[2] -make: Vauxhall
-model: Astra
-year: 1972
I've tried some usort variations:
function typeSort($a, $b)
{
if ($a['model'] == 'Civic' )
{
return 0;
}
return ($a['model'] < $b['model']) ? -1 : 1;
}
but this is just returning 1