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), feed json_decode( json_encode($phparray), true ), give exact object json_decode("sales.json") file?
  • (or) how can feed json_decode function php array() object have?

actually, json_decode returns std object, not array. array json string need use json_decode($string, true).


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -