【发布时间】:2013-02-21 04:08:11
【问题描述】:
假设您有以下数组值分配给一个变量,
$erz = Array (
[0] => stdClass Object ( [id] => 43 [gt] => 112.5 )
[1] => stdClass Object ( [id] => 47 [gt] => 46 )
[2] => stdClass Object ( [id] => 48 [gt] => 23.75 )
[3] => stdClass Object ( [id] => 49 [gt] => 12.5 )
)
我需要能够获得给定 id 的数组索引号。因此,例如我想得到 2 个给定 id 48,或者得到 3 个给定 id 49,等等。有没有 php 命令能够做到这一点?
【问题讨论】:
-
您可以尝试使用 PhpLinq 来执行此操作,它与 .Net 版本非常相似。查看以下链接以获取更多信息。 tech.pro/tutorial/797/basic-linq-syntax-in-php-with-phplinq 它可能不是您要获取的索引,但它会返回整个项目。
-
如果是
id,为什么不首先将该标识符作为数组/哈希索引?