PHP Object converted to JSON Object


<?php


#PHP Objects with StdClass

#Serialisation : Converting One type of Object to another Type of Object

#PHP Object converted to JSON Object


$studentobj  = new StdClass();


$studentobj->name = 'Awnish'; #string

$studentobj->newclass = "12th"; #string

$studentobj->marks = 97; #integer

$studentobj->passed = true; #boolean

$studentobj->college = "IT College"; #boolean


#var_dump($studentobj);

#echo "<hr/>";

header("Content-Type:application/json");


#Terminate After data

echo json_encode($studentobj,JSON_PRETTY_PRINT);

exit;