How can objects be used to handle data manipulation in PHP?
Objects can be used in PHP to handle data manipulation by creating classes that encapsulate data and methods to manipulate that data. By creating objects from these classes, you can easily organize and manipulate data in a structured way.
class User {
public $name;
public $email;
public function __construct($name, $email) {
$this->name = $name;
$this->email = $email;
}
public function displayUserInfo() {
echo "Name: " . $this->name . "<br>";
echo "Email: " . $this->email . "<br>";
}
}
$user1 = new User("John Doe", "john.doe@example.com");
$user1->displayUserInfo();