0

Using var_dump from an API call give me the output like this

enter image description here

How to put them into an array? thanks

  • 2
    Presumably this is the result of `json_decode($api_return_data)`? If so, just change the call to `json_decode($api_return_data, true)` and you will get an associative array instead of an object. – Nick Nov 19 '18 at 06:24
  • Possible duplicate of [Convert stdClass object to array in PHP](https://stackoverflow.com/questions/19495068/convert-stdclass-object-to-array-in-php) – Nick Nov 19 '18 at 06:35

1 Answers1

2

You can use json_encode to convert it to a json. After which you can use json_decode with the second parameter set to true which will return an array instead of an StdObject.

If the api you're calling simply returns a json itself then you can go ahead and use json_decode directly with the second argument set to true to yield the same result.

There are other ways, but this is the simplest.

You can check out other questions, like this one or this one.

Andrei
  • 3,434
  • 5
  • 21
  • 44