What are the advantages of storing values in an array before outputting them in PHP?

Storing values in an array before outputting them in PHP can make the code more organized and efficient. It allows for easier manipulation of the data before displaying it, such as sorting or filtering. Additionally, it can improve performance by reducing the number of database queries or API calls needed to retrieve the data for each output.

// Storing values in an array before outputting them
$data = array('value1', 'value2', 'value3');

// Outputting the values from the array
foreach ($data as $value) {
    echo $value . "<br>";
}