我想知道如何从下面显示的print_r中获取值

时间:2012-10-12 08:05:39

标签: php arrays stdclass

这是

的结果

print_r($response->Items->Item->EditorialReviews->EditorialReview)

 Array
        (
            [0] => stdClass Object
                (
                    [Source] => Product Description
                    [Content] => Acer AO725-0899
                    [IsLinkSuppressed] => 
                )

            [1] => stdClass Object
                (
                    [Source] => Amazon.com Product Description
                    [Content] => Perfect portability, perfect usability: The Aspire® One AO725 N

我希望从0到Content或1到Content的值,我怎样才能得到这个?

4 个答案:

答案 0 :(得分:1)

继续关注链:

$response->Items->Item->EditorialReviews->EditorialReview[0]->Content

$response->Items->Item->EditorialReviews->EditorialReview[1]->Content

从转储中查找所需数据的一般规则:

  1. 任何Array( [x] => ...表示您将[0]附加到您的变量。

  2. 任何Object( [x] => ...表示您将->x附加到您的变量。

答案 1 :(得分:1)

$response->Items->Item->EditorialReviews->EditorialReview[0]->Content

答案 2 :(得分:1)

听起来很简单:

echo $response->Items->Item->EditorialReviews->EditorialReview[0]->Content;

贯穿所有这些:

foreach($response->Items->Item->EditorialReviews->EditorialReview as $review)
   echo $review->Content;

答案 3 :(得分:1)

试试这个:

echo $response->Items->Item->EditorialReviews->EditorialReview[0]->Content;  //for 0 contect
echo $response->Items->Item->EditorialReviews->EditorialReview[1]->Content;  //for 1 content

$response->Items->Item->EditorialReviews->EditorialReview是一个数组..使用你想要获得值的索引,如...

阵列[指数];

如果对象使用.... - > yourvalue