PHP to feed the json_decode() function with an PHP Array? -
i have proper .json
physical file , read php parsing it.
let's sales.json
contains:
{ "custid" : "7761", "items" : [ { "itemcode" : "a11231g", "suppliers" : [ { "id" : "s10001", "name" : "benny & john", }, { "id" : "s10004", "name" : "colorado dimension", } ] } ] }
then consume php:
$sales = json_decode( file_get_contents("store/sales.json"), true );
there no problem , $sales
become array ok.
now reason, want feed json_decode()
function php array (instead of .json
physical file).
i know dumb way doing converting, array
-> json
-> array
, array
array
.
but whatever reason have,
- even if have php array() with correct structure, if use
json_encode($phparray)
, feedjson_decode( json_encode($phparray), true )
, give exact objectjson_decode("sales.json")
file? - (or) how can feed
json_decode
function phparray()
object have?
actually, json_decode returns std object, not array. array json string need use json_decode($string, true)
.
Comments
Post a Comment