0

i want get data from stdclass object. i use foreach method to get key and value. with var_dump i can get all infromation about the post, buy i want extract all 'display'.

foreach($data as $key=>$value){
                var_dump($value);
            }

var_dump result :

var_dump result :

i just want extract all display_ur property. can anyone exlain me ?

1
  • var_dump($value->node->display_url); Commented Sep 16, 2019 at 11:12

4 Answers 4

2

do like below:-

foreach($data as $key=>$value){
    foreach($value as $val){
        echo $val->node->display_url;
        echo PHP_EOL;
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

@Wilson glad to help you. check my modified answer for your help
1

Your original array is made out of stdClassObjects. Each of these class objects has a public property called node that is also a stdClassObject.

That means that if you want to retrieve the display_url for each of these objects, you need:

foreach ($array as $object) {
   $node = $object->node;
   var_dump($node->display_url); // this should return what you are looking for
}

2 Comments

Thank you very much. Now i want to extract specific display_url. as yo can see data is array 0 to 5. i want get one by one without var_dump. how can i do this ?
If I understand correctly, you want to have the display_url values to work with afterwards. You can replace the var_dump statement with something like $displayUrlList [] = $node->display_url; and initialize $displayUrlList = [] before the foreach statement. Afterwards you will get an array containing only the display_url values
0

$value->display_url. I think this will work for you.

2 Comments

Error : Undefined property: stdClass::$display_url
$value->node->display_url
0

With type cast

 $array=(object) $stdClassObject;


foreach($array as $key=>$value){
                var_dump($value);
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.