On this page
- 1 Class and Object Example in PHP
- 2 Class and Object Example in PHP
- 2.0.0.1 CRUD App in PHP
- 2.0.0.2 Understanding PHP’s Array Manipulation: Exploring References and Unsetting
- 2.0.0.3 PHP built-in functions
- 2.0.0.4 Mastering Dependency Management with Composer: A Comprehensive Guid
- 2.0.0.5 Associative Array Example in PHP
- 2.0.0.6 PHP: Sum of two number
- 2.0.0.7 PHP How to get first and last name from full name?
- 2.0.0.8 How to create CSV file in PHP?
- 2.0.0.9 PHP: serialize() Function
- 2.0.0.10 Cheatsheet: PHP
- 2.0.0.11 PHP: global variable
- 2.0.0.12 Understanding PHP Error Reporting Configuration
- 2.0.0.13 PHP: Date and Time Function
- 2.0.0.14 PHP : Function
- 2.0.0.15 PHP: JSON Encode and Decode
- 2.0.0.16 PHP: Scrap Images Using cURL
- 2.0.0.17 What is curl in php?
- 2.0.0.18 PHP: Quiz App
- 2.0.0.19 PHP Tutorials
- 2.0.0.20 PHP: Arrays
- 2.1 Leave A Comment Cancel reply
Class and Object Example in PHP
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"}