What are the advantages and disadvantages of using aggregate functions in PHP for data manipulation?

When working with large datasets in PHP, using aggregate functions can simplify data manipulation tasks by allowing you to perform calculations on groups of data rather than individual records. However, using aggregate functions can also introduce performance issues, especially when dealing with very large datasets, as they require processing a large amount of data at once.

// Example of using aggregate functions in PHP to calculate average salary
$employees = [
    ['name' => 'Alice', 'salary' => 50000],
    ['name' => 'Bob', 'salary' => 60000],
    ['name' => 'Charlie', 'salary' => 70000]
];

$totalSalary = array_sum(array_column($employees, 'salary'));
$averageSalary = $totalSalary / count($employees);

echo "Average salary: $averageSalary";