我需要从这个数组中删除 Jackie Jackson,我尝试了 unset(我不想使用密钥)、array_diff、array_search。没有什么对我有用。$employeeList= array( array( "ID" => "ID", "Name" => "Name", "Surname" => "Surname", ), array( "ID" => 1, "Name" => "John", "Surname" => "Smith", ), array( "ID" => 2, "Name" => "Jackie", "Surname" => "Jackson", ), array( "ID" => 3, "Name" => "Chris", "Surname" => "Jones", ), array( "ID" =>4, "Name" => "Amanda", "Surname" => "Cullen", ), array( "ID" =>5, "Name" => "Jeremy", "Surname" => "Goodwin", ), );
2 回答
MMMHUHU
TA贡献1834条经验 获得超8个赞
如果您想取消设置,您可以使用 Jackie Jackson 的 id 来匹配他的密钥。
$id = 2;
unset($employeeList[array_search($id,array_column($employeeList, "ID"))]);
玩得开心 :)
小唯快跑啊
TA贡献1863条经验 获得超2个赞
数组过滤器来检查名字和姓氏是否匹配。在这种情况下,字符串必须包含由空格分隔的姓名和姓氏,以便我们可以“分解”并单独提取每个人。如果 name 或 surname 在“name_to_exclude”中不存在,该函数将简单地返回原始数组。
$name_to_exclude = "Jackie Jackson";
$exclude = explode(' ', $name_to_exclude);
$employeeList = array_filter($employeeList, function($val) use ($exclude) {
if(array_key_exists(0, $exclude) && array_key_exists(1, $exclude)) {
return $val['Name'] != $exclude[0] && $val['Surname'] != $exclude[1];
}
return true;
});
- 2 回答
- 0 关注
- 166 浏览
添加回答
举报
0/150
提交
取消