PHP Simple object and array conversion function code (PHP multi-layer Array and object conversion)
PHP multi-layer array and object conversions
Multi-layer arrays and object conversions are simple to handle the conversion of multiple arrays and objects in WebService
Simple (array) and (object) can only handle single-layer data, and there is nothing to do with multi-layered arrays and object conversions.
You can convert an object to an array one time through Json_decode (the $object), but there is a problem with non-ASCII characters that are not utf-8 encoded in object, such as GBK's Chinese, not to mention Json_ The performance of encode and decode is also questionable.
Foo = "Test data"; $init->bar = new StdClass; $init->bar->baaz = "testing"; $init->bar->fooz = new StdClass; $init->bar->fooz->baz = "Testing Again"; $init->foox = "Just test"; Convert array to object and then object back to Array $array = Objecttoarray ($init); $object = Arraytoobject ($array); Print objects and Array print_r ($INIT); echo "\ n"; Print_r ($array); echo "\ n"; Print_r ($object);?>