fork download
  1. <?php
  2.  
  3. $row = array("name" => "Baixo Alentejo", "color" => "#f0e68d");
  4.  
  5. $nodes['nodes']['name'] = $row['name'];
  6. $nodes['nodes']['color'] = $row['color'];
  7.  
  8. $nodeEncode = json_encode($nodes);
  9. $nodeDecode = json_decode($nodeEncode);
  10.  
  11. echo "json_encode \n";
  12. var_dump($nodeEncode);
  13.  
  14. echo "json_decode \n";
  15. foreach ($nodeDecode as $node){
  16. echo $node->name . "\n";
  17. echo $node->color . "\n";
  18. }
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
json_encode 
string(53) "{"nodes":{"name":"Baixo Alentejo","color":"#f0e68d"}}"
json_decode 
Baixo Alentejo
#f0e68d