-2

我得到了这个 JSON,但必须知道如何从中提取数据。

我试过$data['success'][0]['success']了,它奏效了

但是我想要像 $getPlayerLimit 这样的东西并返回 1000

Array
(
    [result] => success
    [source] => Array
        (
            [0] => getPlayerLimit
            [1] => getPlayerCount
        )

    [success] => Array
        (
            [0] => Array
                (
                    [result] => success
                    [source] => getPlayerLimit
                    [success] => 1000
                )

            [1] => Array
                (
                    [result] => success
                    [source] => getPlayerCount
                    [success] => 0
                )

        )

)
4

1 回答 1

0

可以迭代数组以找到getPlayerLimit

    foreach($data['success'] as $item)
    {
        if($item['source'] == 'getPlayerLimit')
        {
            /*
                $item looks like:

                Array
                (
                    [result] => success
                    [source] => getPlayerLimit
                    [success] => 1000
                )
            */
            echo 'player limit is: ' . $item['success'];
        }
    }
于 2012-05-04T10:32:59.377 回答