How can objects be used in PHP to store and manipulate data instead of traditional arrays?

In PHP, objects can be used to store and manipulate data instead of traditional arrays by defining a class with properties and methods that represent the data and actions related to it. This allows for more structured and organized data storage, as well as the ability to encapsulate data and behavior within a single entity.

// Define a class to represent a person with properties for name and age
class Person {
    public $name;
    public $age;

    public function __construct($name, $age) {
        $this->name = $name;
        $this->age = $age;
    }

    public function greet() {
        return "Hello, my name is " . $this->name . " and I am " . $this->age . " years old.";
    }
}

// Create a new instance of the Person class
$person = new Person("John", 30);

// Access and manipulate the data using object properties and methods
echo $person->greet(); // Output: Hello, my name is John and I am 30 years old.