What is the best approach to handle a two-dimensional array in PHP where certain values need to be aggregated based on specific conditions?

When handling a two-dimensional array in PHP where certain values need to be aggregated based on specific conditions, the best approach is to use nested loops to iterate through the array and apply the aggregation logic as needed. You can use conditional statements within the loops to check for the specific conditions and update the aggregated values accordingly.

<?php

// Sample two-dimensional array
$data = [
    [10, 20, 30],
    [15, 25, 35],
    [20, 30, 40]
];

// Initialize variables for aggregated values
$sum = 0;

// Iterate through the array and aggregate values based on specific conditions
foreach ($data as $row) {
    foreach ($row as $value) {
        if ($value > 20) {
            $sum += $value;
        }
    }
}

// Output the aggregated sum
echo "Aggregated sum: " . $sum;

?>