I want to know how can I get the value from this print_r shown below

笑着哭i 提交于 2019-12-12 06:30:09

问题


Here's the result of

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

I want to get the value from 0 to Content or 1 to Content , How can I get this?


回答1:


Just keep following the chain:

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

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

General rule to finding the data you want from a dump like this:

  1. Anything Array( [x] => ... means you append [0] to your variable.

  2. Anything Object( [x] => ... means you append ->x to your variable.




回答2:


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



回答3:


Sounds simple enough:

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

To run through all of them:

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



回答4:


try this:

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 is an array.. use the index of which u want to get the value like...

array[index];

if object use.... ->yourvalue



来源:https://stackoverflow.com/questions/12854749/i-want-to-know-how-can-i-get-the-value-from-this-print-r-shown-below

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!