有没有一种方法可以在不遍历所有数组的情况下从知道值的关联数组中获取值?

Is there a way to take a value from associate array knowing the value without iterating through all the array?

我想从数组中获取一个值,例如 Win,其中 UName = demo123,在本例中为 66

我有大约 2k 个实体的数组,这些只是其中的前 2 个。

[0] => Array

    (
        [Win] => 23
        [BookID] => 1863
        [Name] => Second Book Name
        [UName] => example
        [UserID] => 4916
    )

[1] => Array
    (
        [Win] => 66
        [BookID] => 467
        [Name] => BookName
        [UName] => demo123
        [UserID] => 269
    )

我知道我可以通过这样的循环获取值

foreach ($d['author'] as $author) {
     if ($author['UName'] == 'demo123') {
         $win += $author['Win'];
     }
}

但是有没有简单的方法和函数来做到这一点?

不,没有。即使有,该函数也可能会执行一个循环,因为这是在这样的数组中查找值的唯一方法。