This outputs the following: $objectOverview: Array ( => stdClass Object ( => Hello $bodyMessage=imap_fetchbody($imap,$count,1) Print 'objectDate ='.($objectOverview->date) Print 'objectSubject ='.($objectOverview->subject)) $objectOverview: ' print_r($objectOverview) The following code will read all emails & print the Subject, Body & Date. Tested and working with complex arrays where a stdClass object can contain other stdClass objects. Public 'bbb' => string 'adsf43' (length = 6) Public 'aaa' => string 'asdf' (length = 4) $array = arra圜astRecursive((array)$value) You may want a recursive cast, which would look something like this: function arra圜astRecursive($array) Since it's an array before you cast it, casting it makes no sense. Hence the following line will convert your entire object into an array: $array = json_decode(json_encode($booking), true) When TRUE, returned objects will be converted into associative arrays. The manual specifies the second argument of json_decode as: Support for 5.1 stopped in 2006.)Ĭonverting an array/ stdClass -> stdClass $stdClass = json_decode(json_encode($booking))
Php class to array update#
If you use any older version there's also a PECL library (that said, in that case you should really update your PHP installation. These are automatically bundled in PHP 5.2.0 and up. Not exactly - you used json_decode on the array, but you need to encode it with json_encode first. You can do this in a one liner using the JSON methods if you're willing to lose a tiny bit of performance (though some have reported it being faster than iterating through the objects recursively - most likely because PHP is slow at calling functions).