如何在PHP多维数组中找到索引位置匹配的键
我有一个多维数组。我想找到数组中给定键的位置 我的阵列如何在PHP多维数组中找到索引位置匹配的键,php,multidimensional-array,Php,Multidimensional Array,我有一个多维数组。我想找到数组中给定键的位置 我的阵列 Array ( [200] => Array ( [totalQuesAttempted] => 10 [totalCorrectQuestion] => 2 ) [100] => Array ( [totalQuesAttempted] => 10
Array
(
[200] => Array
(
[totalQuesAttempted] => 10
[totalCorrectQuestion] => 2
)
[100] => Array
(
[totalQuesAttempted] => 10
[totalCorrectQuestion] => 3
)
[400] => Array
(
[totalQuesAttempted] => 10
[totalCorrectQuestion] => 4
)
[300] => Array
(
[totalQuesAttempted] => 10
[totalCorrectQuestion] => 7
)
[500] => Array
(
[totalQuesAttempted] => 10
[totalCorrectQuestion] => 8
)
)
我正在传递UPID
值,我需要该UPID的索引位置
$UPID = "300";
$result = array_search($UPID, array_values($usersAttemptsInfo));
我的预期输出是3,因为300个索引位置是3所有内容都是正确的,但不是使用
数组值
而是使用数组键
:
$UPID = "300";
$result = array_search($UPID, array_keys($usersAttemptsInfo));
echo $result;