我正在使用php中的rest api并使用mysql query,我得到以下数组(1和2是cat_ids), 我只想将cat_id和cat_image移出数组,我的意思是我想显示第一个带有cat_name的cat_id,在其中我想获取所有具有用户ID的自拍图像,然后第二个cat_name和cat id,在其中我想要获取所有自拍图像和用户ID等
这是我的代码。
foreach($userArr as $k=>$v){
$userCatArr[$v['cat_id']][] = $v; //add node
unset($userCatArr[$v['cat_id']]['cat_id']); //unset doubles
}
$userArr = $userCatArr; unset($userCatArr);
print_R($userArr);
我正在关注结果
Array
(
[1] => Array
(
[0] => Array
(
[id] => 16
[cat_id] => 1
[user_id] => 4
[cat_image] => abcd.jpg
[selfie_image] => abc.jpg
)
[1] => Array
(
[id] => 17
[cat_id] => 1
[user_id] => 4
[cat_image] => xyze.jpg
[selfie_image] => xyz.jpg
)
)
[2] => Array
(
[0] => Array
(
[id] => 16
[cat_id] => 2
[user_id] => 4
[cat_image] => abcdee.jpg
[selfie_image] => abc.jpg
)
)
但是我想更改如下数组的结果
Array
(
[cat_id] => 1
[cat_image] => abc.jpg
(
[0] => Array
(
[user_id] => 4
[selfie_image] => abc.jpg
)
[1] => Array
(
[user_id] => 4
[selfie_image] => xyz.jpg
)
)
[cat_id] => 2
[cat_image] => xyz.jpg
(
[0] => Array
(
[user_id] => 4
[selfie_image] => abc.jpg
)
)