Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.php Subject: Re: parsing print_r() output with preg_match_all() Date: Thu, 14 Jan 2016 08:34:03 +0100 Lines: 83 Message-ID: <56974F6B.1040705@arnowelzel.de> References: <568d3dcf$0$23748$e4fe514c@news.xs4all.nl> <87r3huzevd.fsf@bsb.me.uk> <568d6f9c$0$23759$e4fe514c@news.xs4all.nl> <569363A3.6040108@arnowelzel.de> <5694313D.3060100@arnowelzel.de> <6929015.zlp62RpN2j@PointedEars.de> <569483AF.6010606@arnowelzel.de> <56956576.3040909@arnowelzel.de> <56956FF5.3050603@arnowelzel.de> <5695E316.9050809@arnowelzel.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: individual.net AEj+STramiw7pACc/+TaPAkFPbICCu3XUQc3L3Hf7YEuCLAR3Y Cancel-Lock: sha1:91zNuafzLHjl0dQNay08D1YgbAc= In-Reply-To: Xref: csiph.com comp.lang.php:16265 Jerry Stuckle schrieb am 2016-01-14 um 01:18: > On 1/13/2016 6:14 PM, Ian Collins wrote: [...] >> Given the first example on the print_r() manual page, do you think >> anyone who understands this: >> >> > $a = array ('a' => 'apple', 'b' => 'banana', >> 'c' => array ('x', 'y', 'z')); >> print_r ($a); >> ?> >> >> Array >> ( >> [a] => apple >> [b] => banana >> [c] => Array >> ( >> [0] => x >> [1] => y >> [2] => z >> ) >> >> ) >> >> would have trouble understanding this? >> >> > $a = array ('a' => 'apple', 'b' => 'banana', >> 'c' => array ('x', 'y', 'z')); >> echo json_encode($a,JSON_PRETTY_PRINT); >> ?> >> >> { >> "a": "apple", >> "b": "banana", >> "c": [ >> "x", >> "y", >> "z" >> ] >> } >> > > Yes. The former is much more clear. If something is "more clear" totally depends on what people are used to work with. In fact both textual representations are perfectly *readable*. On can *read* the content. If one does not have any experience with XML, even this may not be clear to him: And is the key always a string or will numbers be treated different? In JSON it is possible to differentiate the data type as well, if needed: { "a": "apple", "b": "banana", "c": [ 1, 2, 3 ] } -- Arno Welzel http://arnowelzel.de http://de-rec-fahrrad.de http://fahrradzukunft.de