Trying to sort my array to show the group with meat categoryName to be first element in array. Is there a better way to sort this array than running two for loops?
My array looks like this
Array
(
[0] => Array
(
[categoryId] => C4ye95zr403cx9wqi11eo
[categoryName] => set
[categoryStatus] => true
)
[1] => Array
(
[categoryId] => Cj-v2b7szu3jpph1rvu03
[categoryName] => meat
[categoryStatus] => true
)
I want to rearrange the array by categoryName == meat to be first element in array.
Currently i'm just running two loops to do this.
$temp = array();
foreach($array as $k => $v)
{
if($v['categoryName']=="meat")
{
$temp[] = $menu[$k];
$setEmpty = false;
unset($array[$k]);
}
}
foreach($menu as $k=>$v)
{
$temp[] = $array[$k];
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…