01 PHP JSON array

01 PHP JSON array

    $myObj2 = array("Peter"=>35, "Ben"=>37, "Joe"=>43);
    echo json_encode($myObj2);
    
    
    
    class Emp {
    	public $name = "";
    	public $age  = "";
    	public $city = "";
    }
    $myObj = new Emp();
    $myObj->name = "John";
    $myObj->age = 30;
    $myObj->city = "New York";
    
    $myJSON = json_encode($myObj);
    echo $myJSON;
    

    輸出:
    {“Peter”:35,”Ben”:37,”Joe”:43}
    {“name”:”John”,”age”:30,”city”:”New York”}