Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: jazdian
Added: Apr 5, 2018 4:05 PM
Modified: Apr 5, 2018 4:24 PM
Views: 29
Tags: json object php
Create a object based in a json string PHP.
  1. $JsonString = '{"Element1":{"item1":1,"item2":"val2","item3":"val3"},"Element2":{"item1":1,"item2":"val2","item3":"val3"}}';
  2. $Object = json_decode($JsonString);
  3.  
  4. //Get Elemets and items
  5. $GetElemet1 = $Object->Element1;
  6. $GetItem11 = $GetElemet1->item1;
  7. $GetItem12 = $GetElemet1->item2;
  8. // OR
  9. $GetItem21 = $Object->Element2->item1;
  10. $GetItem22 = $Object->Element2->item2;