0

I trying to get data from a webservices using php curl. I get this data var_dump($result) result is

string(136) "array(1) { [0]=> object(stdClass)#10 (2) { ["guid"]=>    string(23) "149063186158d93cb600485" ["stage"]=> int(0) } } "

I want to get guid and stage. When I use this code

$result->guid 

I get an error. How can I solve this problem?

Notice: Trying to get property of non-object in

print_r($result) is array(1) { [0]=> object(stdClass)#10 (2) { ["guid"]=> string(23) "149063186158d93cb600485" ["stage"]=> int(0) } }
Fatih
  • 235
  • 1
  • 4
  • 15
  • 1
    try `$result[0]->guid ` – Chetan Ameta Mar 28 '17 at 08:51
  • I tried such as I get same error. – Fatih Mar 28 '17 at 08:52
  • 1
    You have a string here. Show us your code, which created this string. – Rizier123 Mar 28 '17 at 08:53
  • Check the best answer here: http://stackoverflow.com/questions/3531857/convert-var-dump-of-array-back-to-array-variable – Hossam Mar 28 '17 at 08:54
  • I'm using curl. Returning data is as I showed. – Fatih Mar 28 '17 at 08:54
  • 2
    @Fatih can u show me the content by using ```print_r()``` once. – Suresh Mar 28 '17 at 08:55
  • print_r($result) is array(1) { [0]=> object(stdClass)#10 (2) { ["guid"]=> string(23) "149063186158d93cb600485" ["stage"]=> int(0) } } – Fatih Mar 28 '17 at 08:56
  • This looks like a `var_dump` of a `var_dump` of an `array`. – WasteD Mar 28 '17 at 08:56
  • are you having any object or just a string? because var_dump display string(136) menas that is an string not an object or array? can you confirm the same – Chetan Ameta Mar 28 '17 at 08:58
  • from ```print_r``` output it seems ```$result[0]->guid``` should work. Use ```json_encode``` & show me the result once. That'll help to see the things in our own local environment. – Suresh Mar 28 '17 at 09:07
  • The output you posted says `$result` contains the output of a `var_dump()` call and that one is not JSON and cannot be easily decoded into something useful. Please post the raw JSON you get from the remote service. – axiac Mar 28 '17 at 10:01
  • Possible duplicate of [How can I access an array/object?](http://stackoverflow.com/questions/30680938/how-can-i-access-an-array-object) – user3942918 Mar 28 '17 at 21:36

1 Answers1

1
echo (is_array($result)) ? $result[0]->guid : $result->guid;
Amir Helmy
  • 121
  • 2
  • 3