Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "J.O. Aho" Newsgroups: comp.lang.php Subject: Re: JSON encode "corrupted"? Date: Thu, 5 Aug 2021 21:49:48 +0200 Lines: 31 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net lyjhxfxwucXyNVbt2/4DMgL+vYwxjotabwnp8au7i5zzHYz4R0 Cancel-Lock: sha1:QfwdkWeMR1d2hJp39DKVexVy8Yc= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 In-Reply-To: Content-Language: en-US-large Xref: csiph.com comp.lang.php:18763 On 05/08/2021 21:25, Torakiki wrote: > > > 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); > > ?> > > IMHO, seem to be a bug! nope, not a bug, just a standard how to represent different types of arrays. https://cswr.github.io/JsonSchema/spec/arrays/