Laravel,如何删除特定位置数组中的键和值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45627316/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:29:28 来源:igfitidea点击:
Laravel, how to delete key and value in an array of a specific position?
提问by begineeeerrrr
回答by
you can do this just with one foreach!
你可以用一个 foreach 来做到这一点!
foreach ($data as $key => $subArr) {
unset($subArr['id']);
$data[$key] = $subArr;
}
回答by Moby M
Instead of doing foreach()
loop on the array, You can go with array_search()
而不是foreach()
在数组上做循环,你可以去array_search()
$results=array_search($unwantedValue,$array,true);
if($results !== false) {
unset($array[$result]);
}
回答by chanafdo
You can use the following
您可以使用以下
$filteredArray = array_map(function($array) {
unset($array['id']);
return $array;
}, $dataArray);