June 2017
Intermediate to advanced
536 pages
9h 49m
English
Over the years, the JSON data format has become somewhat of a default data exchange format for REST. The simplicity of JSON made it quite popular with PHP developers. Out of the box, the PHP language provides the json_encode() and json_decode() functions. Using these functions, we can easily encode PHP arrays and objects as well as decode various JSON structures.
The following example demonstrates the simplicity of using the json_encode() function:
<?phpclass User{ public $name; public $age; public $salary;}$user = new User();$user->name = 'John';$user->age = 34;$user->salary = 4200.50;echo json_encode($user);// {"name":"John","age":34,"salary":4200.5}$employees = ['John', 'Mariya', 'Sarah', 'Marc'];echo json_encode($employees ...
Read now
Unlock full access