php json_encode
snippet in php

php json_decode

user1256

$personJSON = '{"name":"Johny Carson","title":"CTO"}';

$person = json_decode($personJSON);

echo $person->name; // Johny Carson

json_encode php

user654


  <?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");

  
echo json_encode($age);
?>
 

php json_encode

user5589

$person = array( 
    "name" => "Johny Carson", 
    "title" => "CTO"
); 
$personJSON=json_encode($person);//returns JSON string

php echo json

user841

<?php
$data = ['name' => 'John', 'age' => 35];
header('Content-type: Application/json');
echo json_encode($data);