Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP多维数组中找到索引位置匹配的键_Php_Multidimensional Array - Fatal编程技术网

如何在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;