I have a foreach loop that searches through files and creates arrays for that files and it all works as intended. In the foreach loop I create a $total variable adding a set amount of the values in that loop to each other. I would like to add all of the $total's at the end of my code, which I figure could be achieved by sending each $total automatically to a seperate array outside the loop, and then using an array_sum() function, but I'm struggling. Here is an example of my code -->
<?php
foreach($file as $client) {
$name = $client;
$document = "client/" . $name . "";
$client_data = file_get_contents($document);
$data = explode("\t",$client_data_);
$total = $data[0] + $data[1] + $data[2] + $data[3];
}
?>
And then of course to send that $total to an array to add together... I have no clue on how to do this... any tips/solutions?
Apologies if this is ignorant, or badly worded.. I'm a student and relatively new to the coding stuff (and want to get good marks).