config Object ( [a] => test a [b] => stdClass Object ( [b_arr] => test b [c] => Array ( [c_arr] => test c ) ) ) 1. config Object ( [a] => test a [b] => stdClass Object ( [b_arr] => test b [c] => Array ( [c_arr] => test c ) ) ) however when i use the method as recursive i get….
site design / logo © 2020 Stack Exchange Inc; user contributions licensed under
ARRAY_N - result will be output as a numerically indexed array of numerically indexed arrays. I add for this function parameter true, but still i have empty arrayif i use true then i have empty array. Childrens array still are stdObject@LucciFangorci You didn't mentioned, that you want the whole tree.
OBJECT_K - result will be output as an associative array of row objects, using first columns values as keys (duplicates will be discarded).
Array to stdClass can be done in php this way.
– deceze ♦ Jul 9 '12 at 13:56 When should I use one or the other? The Overflow Blog Where developers & technologists share private knowledge with coworkersProgramming & related technical career opportunitiesi use json and json_decode function. and i dont know how to traverse it, and how could I get array like thisThe easiest way is to JSON-encode your object and then decode it back to an array:Or if you prefer, you can traverse the object manually, too:Very simple, first turn your object into a json object, this will return a string of your object into a JSON representative.Take that result and decode with an extra parameter of true, where it will convert to associative arrayARRAY_A is a “output_type” argument. ARRAY_A - result will be output as an numerically indexed array of associative arrays, using column names as keys.
Featured on Meta While iterating through it, access the property you want @Petah yes but i think he will have to use foreach too.
For now I don't even see a reason, why: since you've got objects inside of objects, you'll need to cast the containing object to an array and iterate it.
I think every PHP coders have come accross Arrays and stdClass Objects (belongs to PHP Predefined Classes). Fatal error: Cannot use object of type stdClass as array inIs possible parse this stdClass to array and use this with keys?If not, what everybody else has said and just type cast itYour problem is probably solved since asking, but for reference, quick uncle-google answer:Cast it into an array.
PHP. your coworkers to find and share information. Stack Overflow for Teams is a private, secure spot for you and Free 30 Day Trial It can be one of four pre-defined constants (defaults to OBJECT):While converting a STD class object to array.Cast the object to array by using if you have array and array element is stdClass item then this is the solutionnow the stdClass has been replaced with array inside the array as new array elementUsing the ArrayObject from Std or building your own Questions: What are the differences between htmlspecialchars() and htmlentities(). Using json_decode(json_encode(), true) to simplify stdclass object to an associative array, because it is sometimes complicated to work with multiple mixed object and array in a single variable. This is easy if arrays and objects are one-dimensional, but might be little tricky if using multidimensional arrays …
If i use yout solution this working only for current array - children array still are stdClassthis working only for current array.