note 113290 deleted from function.json-encode by peehaa

From: Date: Sun, 22 Sep 2013 13:37:41 +0000
Subject: note 113290 deleted from function.json-encode by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-196345@lists.php.net to get a copy of this message
Note Submitter: maurosys at gmail dot com ---- I don't understand the follow <? class Tipo { public $Id; public $Nome; } for ($i=0;$i<10;$i++) { $categoria = new Tipo(); $categoria->Id = $i; $categoria->Nome = "Categoria número $i"; $categorias[$i] = $categoria; } $inicio = 4; $categorias2 = Array(); for ($i=0;$i<10;$i++) { if ($i < $inicio) continue; $categoria = new Tipo(); $categoria->Id = $i; $categoria->Nome = "Categoria número $i"; $categorias2[$i] = $categoria; } echo "<pre>"; echo json_encode($categorias); /* this return [{"Id":0,"Nome":"Categoria n\u00famero 0"},{"Id":1,"Nome":"Categoria n\u00famero 1"},{"Id":2,"Nome":"Categoria n\u00famero 2"},{"Id":3,"Nome":"Categoria n\u00famero 3"},{"Id":4,"Nome":"Categoria n\u00famero 4"},{"Id":5,"Nome":"Categoria n\u00famero 5"},{"Id":6,"Nome":"Categoria n\u00famero 6"},{"Id":7,"Nome":"Categoria n\u00famero 7"},{"Id":8,"Nome":"Categoria n\u00famero 8"},{"Id":9,"Nome":"Categoria n\u00famero 9"}] */ echo "<br>"; echo json_encode($categorias2); /* this return {"4":{"Id":4,"Nome":"Categoria n\u00famero 4"},"5":{"Id":5,"Nome":"Categoria n\u00famero 5"},"6":{"Id":6,"Nome":"Categoria n\u00famero 6"},"7":{"Id":7,"Nome":"Categoria n\u00famero 7"},"8":{"Id":8,"Nome":"Categoria n\u00famero 8"},"9":{"Id":9,"Nome":"Categoria n\u00famero 9"}} */ ?> why in second call the json_encode add the variable $inicio in my array? there are some config to do? I need always the first mode, but if I use any variable it's added in my return array.

« previous php.notes (#196345) next »