Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #18762

Re: JSON encode "corrupted"?

From Torakiki <torakiki.sanNIENTE@SPAMgmail.com>
Newsgroups comp.lang.php
Subject Re: JSON encode "corrupted"?
Date 2021-08-05 21:25 +0200
Organization Aioe.org NNTP Server
Message-ID <sehdv4$1ah6$1@gioia.aioe.org> (permalink)
References <seh0um$ket$1@gioia.aioe.org>

Show all headers | View raw


 > Why? $array is still just an array with one scalar element.

Try this (last PHP 7.4.22 x64):

<?php

$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

---------------------------------------------
array(1) { 
 
 
                                       [0]=> 
 
 
 
     string(9) "Some text" 
 
 
                                        } 
 
 
 
      string(13) "["Some text"]" 
 
 


array(1) { 
 
 
                                       [1]=> 
 
 
 
     string(9) "Some text" 
 
 
                                        } 
 
 
 
      string(17) "{"1":"Some text"}"
---------------------------------------------

IMHO, seem to be a bug!

-- 
 >> Torakiki

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

JSON encode "corrupted"? Torakiki <torakiki.sanNIENTE@SPAMgmail.com> - 2021-08-05 17:43 +0200
  Re: JSON encode "corrupted"? Arno Welzel <usenet@arnowelzel.de> - 2021-08-05 18:41 +0200
    Re: JSON encode "corrupted"? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-08-05 17:20 +0000
      Re: JSON encode "corrupted"? Arno Welzel <usenet@arnowelzel.de> - 2021-08-08 11:43 +0200
  Re: JSON encode "corrupted"? Torakiki <torakiki.sanNIENTE@SPAMgmail.com> - 2021-08-05 21:25 +0200
    Re: JSON encode "corrupted"? "J.O. Aho" <user@example.net> - 2021-08-05 21:49 +0200
    Re: JSON encode "corrupted"? Arno Welzel <usenet@arnowelzel.de> - 2021-08-08 11:44 +0200

csiph-web