What are some alternative approaches to looping through data multiple times for graphing purposes in PHP?

One alternative approach to looping through data multiple times for graphing purposes in PHP is to store the data in a temporary variable and reuse it as needed, rather than looping through the original data multiple times. This can help improve performance and reduce redundant computations.

// Sample data
$data = [1, 2, 3, 4, 5];

// Store data in a temporary variable
$tempData = $data;

// Loop through data for the first graph
foreach ($tempData as $value) {
    // Generate graph for first set of data
}

// Loop through data for the second graph
foreach ($tempData as $value) {
    // Generate graph for second set of data
}