On this page
Class and Object Example in PHP
July 29, 2023

<?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"}
Previous
WP_List_Table tutorial : How to display data from database to the admin block ?
WP_List_Table tutorial : How to display data from database to the admin block ?Next
Associative Array Example in PHP
Associative Array Example in PHP



