【发布时间】:2011-06-24 00:36:43
【问题描述】:
假设我在 PHP 中有一个对象数组,例如:
Array (
[0] => stdClass Object (
[id] => 1
[name] => Title One
)
[1] => stdClass Object (
[id] => 2
[name] => Title Two
)
[2] => stdClass Object (
[id] => 7
[name] => Title Seven
)
)
获取 ID 数组的最佳方式(即最快)是什么?即array(1,2,7)我可以手动循环,但我觉得一定有更好的方法。
刚刚看到this in the similar questions,但对于接受的答案是否真的是最好的方法存在一些争论,而且它是从 2 年前开始的。我在 PHP 5.3 上。
【问题讨论】:
-
根据您的方案,您可能需要考虑使用associative array,而不是具有
id成员的对象数组。
标签: php