How can separating data from formatting improve the efficiency and flexibility of PHP code?

Separating data from formatting in PHP code improves efficiency and flexibility by allowing for easier maintenance and updates. By storing data separately from the presentation layer, changes to the data can be made without affecting the code logic or structure. This separation also enables reusability of data across different parts of the application, promoting a more modular and scalable design.

<?php

// Data stored separately
$data = [
    'name' => 'John Doe',
    'age' => 30,
    'email' => 'johndoe@example.com'
];

// Formatting the data
echo "Name: " . $data['name'] . "<br>";
echo "Age: " . $data['age'] . "<br>";
echo "Email: " . $data['email'] . "<br>";

?>