<?php
class Data {

    public $data;

    function setData($data){
        $this->data = $data;
    }

    function getData(){
        return $this->data;
    }
}


$data = new Data();


$data->setData(
    array(
        "name"=>"John Doe",
        "age"=>20,
        "company_name"=> "XYZ"
    )
);

echo json_encode($data->getData()). "\n";


$dataE1 = new Data();


$dataE1->setData(
    array(
        "name"=>"John Doe 1",
        "age"=>21,
        "company_name"=> "ABC"
    )
);

echo json_encode($dataE1->getData()). "\n";
?>

Output:

{"name":"John Doe","age":20,"company_name":"XYZ"}
{"name":"John Doe 1","age":21,"company_name":"ABC"}

Leave A Comment