Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.php Subject: Re: JSON encode "corrupted"? Date: Sun, 8 Aug 2021 11:44:50 +0200 Lines: 38 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 7bit X-Trace: individual.net fyRKS3bXTicN0cNaItadsA+sG3CdlVASkPd7aTr/uMrfgKSZ+r Cancel-Lock: sha1:+Kb255eD1QAPudsVP9uF8kQO9i4= In-Reply-To: Xref: csiph.com comp.lang.php:18765 Torakiki: > > > Why? $array is still just an array with one scalar element. > > Try this (last PHP 7.4.22 x64): > > > $array=[]; > $array[0]="Some text"; > var_dump($array); > > $json=json_encode($array); > var_dump($json); > > > $array=[]; > $array[1]="Some text"; > var_dump($array); > > $json=json_encode($array); > var_dump($json); > > ?> > > you get Can you PLEASE format your output to NOT take up so much space, thank you! And no this is not a bug, since JSON arrays can't have keys and therefor PHP MUST create a JSON object list instead of an array. -- Arno Welzel https://arnowelzel.de