1<?php
2$data = ['name' => 'John', 'age' => 35];
3header('Content-type: Application/json');
4echo json_encode($data);
5
1$personJSON = '{"name":"Johny Carson","title":"CTO"}';
2
3$person = json_decode($personJSON);
4
5echo $person->name; // Johny Carson
1$person = array(
2 "name" => "Johny Carson",
3 "title" => "CTO"
4);
5$personJSON=json_encode($person);//returns JSON string
1$function = "#!!function(){}!!#";
2$message = "Hello";
3
4$json = array(
5 'message' => $message,
6 'func' => $function
7);
8$string = json_encode($json);
9$string = str_replace('"#!!','',$string);
10$string = str_replace('!!#"','',$string);
11echo $string;
12