<?php $data = ['name' => 'John', 'age' => 35]; header('Content-type: Application/json'); echo json_encode($data);
$person = array( "name" => "Johny Carson", "title" => "CTO" ); $personJSON=json_encode($person);//returns JSON string
<?php $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); echo json_encode($age); ?>