解析php数组中的值

时间:2011-03-21 06:33:39

标签: php arrays multidimensional-array

我是PHP的新手,请帮我解决这些问题。下面是编写的代码,后面是其结果。如何以最有效的方式访问[property]内的[count]。 代码

echo '<pre>';
   print_r($result);
  echo '</pre>';

输出

Array
(
    [0] => Array
        (
            [property] => Array
                (
                    [href] => http://www.example.com
                    [count] => 2
                    [sample] => Array
                        (
                        )

                    [data] => Array
                        (
                            [0] => 100002067610524
                            [1] => 675985591
                        )

                    [users] => 
                    [active] => 1
                )

        )

)

2 个答案:

答案 0 :(得分:3)

不是最有效的,但唯一可能的; - )

echo $result[0]['property']['count'];

答案 1 :(得分:2)

如果您有多个元素,请使用此

foreach($result as $childArray)
{
    echo $childArray['property']['count'];   
}

如果你只有一个元素,那么使用

$array = $result[0]['property']['count'];