How can the code provided in the forum thread be improved to display all data values instead of just the last one?

The issue with the current code is that it is overwriting the value of the $data variable in each iteration of the loop, causing only the last value to be displayed. To display all data values, we can store each value in an array and then print out all the values after the loop completes.

<?php
// Sample data values
$data_values = [10, 20, 30, 40, 50];

// Initialize an empty array to store all data values
$all_data = [];

// Loop through each data value and store it in the array
foreach ($data_values as $value) {
    $all_data[] = $value;
}

// Print out all data values
foreach ($all_data as $data) {
    echo $data . "<br>";
}
?>