Source Code:
(back to article)
<?php $json = '{"name":"John Doe","age":30,"email":"johndoe@example.com"}'; class Person { public $name; public $age; public $email; } $person_array = json_decode($json, true); $person = new Person(); $person->name = $person_array['name']; $person->age = $person_array['age']; $person->email = $person_array['email']; echo $person->name; // "John Doe" echo '-'; echo $person->age; // 30 echo '-'; echo $person->email; // "johndoe@example.com"
Result:
Report an issue