Google News
logo
PHP Program to Access the values from a PHP object
In the following example of PHP program to access the values from a PHP object :
Program :
<?php
// Define a sample object
$obj = new stdClass();
$obj->name = "John Doe";
$obj->age = 30;
$obj->city = "New York";

// Access values from the object
echo "Name: " . $obj->name . "<br>";
echo "Age: " . $obj->age . "<br>";
echo "City: " . $obj->city . "<br>";
?>
Output :
Name: John Doe
Age: 30
City: New York
In this program, we define a sample object using the `stdClass()` class in PHP. We then assign some values to the object properties using the `->` operator. Finally, we access the values of the object properties using the same operator and print them on the screen using the `echo` statement.