我在Laravel应用程序上工作,因此我有一个关联数组要传递给API端点。在发布到API之前,我想删除img键及其值。我尝试使用未设置的功能,但未删除img键我要删除图像属性的数组 $a[] = [ 0 => array:4 [ "name" => "Martoo nnn" "relationship" => "Spouse" "dob" => "2001-02-03" "img" => "img.png" ] 1 => array:4 [ "name" => "sdsdsd sdsdsd" "relationship" => "Child" "dob" => "2019-04-04" "img" => "img1.png" ] 2 => array:4 [ "name" => "sdsdsd sddds" "relationship" => "Child" "dob" => "2019-04-05" "img" => "img2.png" ] 3 => array:4 [ "name" => "dssdsd dsdsd" "relationship" => "Child" "dob" => "2019-04-02" "img" => "img3.png" ] 4 => array:4 [ "name" => "dssdsd dssdsd" "relationship" => "Child" "dob" => "2019-04-04" "img" => "img4.png" ]];取消设定方法$array = $a;unset($array['img']);//dd($a);
2 回答
宝慕林4294392
TA贡献2021条经验 获得超8个赞
你可以做这样的事情,
foreach ($array as $key => &$value) { // & defines changes will be made @ value itself
unset($value['img']);
}
是的,我不明白您为什么要初始化$a为$a[]?
人到中年有点甜
TA贡献1895条经验 获得超7个赞
$newarray = array_filter($a, function($k) {
return $k != 'img';
}, ARRAY_FILTER_USE_KEY);
并传递这个新数组
- 2 回答
- 0 关注
- 173 浏览
添加回答
举报
0/150
提交
取消