What are some methods to add values from multiple arrays in PHP and output the sum as a single value?

To add values from multiple arrays in PHP and output the sum as a single value, you can use the array_sum() function to calculate the sum of each array separately, and then add the sums together to get the total sum. This method allows you to easily add values from multiple arrays without having to iterate through each array manually.

$array1 = [1, 2, 3];
$array2 = [4, 5, 6];
$array3 = [7, 8, 9];

$sum1 = array_sum($array1);
$sum2 = array_sum($array2);
$sum3 = array_sum($array3);

$totalSum = $sum1 + $sum2 + $sum3;

echo $totalSum; // Output: 45