gpt4 book ai didi

php - 在给定属性值的对象数组中查找数组键

转载 作者:IT王子 更新时间:2023-10-28 23:44:28 25 4
gpt4 key购买 nike

我有一个这样的对象数组:

Array
(
[945] => member Object
(
[id] => 13317
[name] => Test 999
[last_name] => Test 999
)

[54] => member Object
(
[id] => 13316
[name] => Manuel
[last_name] => Maria parra
)

[654] => member Object
(
[id] => 13315
[name] => Byron
[last_name] => Castillo
)

[656] => member Object
(
[id] => 13314
[name] => Cesar
[last_name] => Vasquez
)
)

我需要根据属性值移除其中一个对象。
例如,我想从数组中删除对象 id 13316。

最佳答案

这里是函数式方法:

$neededObjects = array_filter(
$objects,
function ($e) use ($idToFilter) {
return $e->id != $idToFilter;
}
);

关于php - 在给定属性值的对象数组中查找数组键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4166198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com