Monday 17 July 2017

How to convert stdClass object to associative array in php

Use json_encode() and json_decode()

$arr = json_decode(json_encode($yourObject), TRUE);

json_decode() 's second parameter is set to TRUE.

Function definition:

mixed json_decode ( string $json [, bool $assoc = false [, int $depth  > = 512 [, int $options = 0 ]]] )

That will convert your object into an associative array.

Reference:

https://stackoverflow.com/questions/34428702/convert-stdclass-object-to-associative-array-in-php/34428735#34428735

No comments:

Post a Comment

Parenting tips to inculcate learning habits in your kid

Parenting tips to inculcate learning habits in your kid Tip #1) Children do not learn things, they emitate. So, try to do things by yours...