Array
(
[0] => Array
(
[value] => photo-wallpapers
[label] => Фотообои
)
[1] => Array
(
[value] => fresco
[label] => Фреска
)
[2] => Array
(
[value] => panno
[label] => Панно
)
)
[value] => fresco
?$array = [
['value' => 'photo-wallpapers', 'label' => 'Фотообои'],
['value' => 'fresco', 'label' => 'Фреска'],
['value' => 'panno', 'label' => 'Панно'],
['value' => 'fresco', 'label' => 'Test'],
['value' => 'ttt', 'label' => 'WoW'],
];
function sortArrayByFresco(array &$array) {
usort($array, function ($a, $b) {
$isFrescoA = $a['value'] === 'fresco';
$isFrescoB = $b['value'] === 'fresco';
if ($isFrescoA && $isFrescoB) {
return 0;
}
return $isFrescoA ? -1 : $isFrescoB;
});
}
// Test
sortArrayByFresco($array);
print_r($array);
/*
Array
(
[0] => Array
(
[value] => fresco
[label] => Фреска
)
[1] => Array
(
[value] => fresco
[label] => Test
)
[2] => Array
(
[value] => photo-wallpapers
[label] => Фотообои
)
[3] => Array
(
[value] => panno
[label] => Панно
)
[4] => Array
(
[value] => ttt
[label] => WoW
)
)
*/
$array = [
['value' => 'photo-wallpapers', 'label' => 'Фотообои'],
['value' => 'fresco', 'label' => 'Фреска'],
['value' => 'panno', 'label' => 'Панно'],
['value' => 'fresco', 'label' => 'Test']
];
usort($array, function($a, $b){
return $a['value'] <=> $b['value'];
});
var_dump($array);