I have the following array with php
// array stored in $items
Array
(
[0] => Array
(
[description] => some text
[value] => 20
)
[1] => Array
(
[description] => bord
[value] => 5
)
[2] => Array
(
[description] => axe
[value] => 99
)
)
What i want is that the description with bord is alwas the last element. I know that php have the function uasort to write your own custom sort function.
What i've tried is the following
uasort($items, function($a, $b){
if($a['description'] == 'bord'){
return 0;
}
return ($a['description'] < $b['description']) ? -1 : 1;
});
But cant figure out how this works.
update Result after uasort
Array
(
[2] => Array
(
[description] => axe
[value] => 99
)
[1] => Array
(
[description] => bord
[value] => 5
)
[0] => Array
(
[description] => some text
[value] => 20
)
)
If i use the following uasort:
uasort($items, function($a, $b){
if($a['description'] == 'bord'){
return 1;
}
return -1;
});
The result is correct, but i never used $b.