Re: Adding up values
| From: | Miguel Cruz | Date: | Fri, 10 May 2002 06:27:56 +0000 |
| Subject: | Re: Adding up values | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-96910@lists.php.net to get a copy of this message | ||
There's really not much to it. The intval of '-' is 0, so it doesn't cause
any problems.
$numbers = file('path/logfile.txt');
$total = 0;
foreach ($numbers as $num) $total += intval($num);
miguel
On Fri, 10 May 2002, Liam MacKenzie wrote:
> another real basic question, how would I add up all the numbers in a log
> file in this format?
>
> Start log file
> --------------------
>
> 6353
> 3309
> 294
> 762
> 6443
> 6353
> 3309
> -
> -
> -
> -
> -
> -
> 294
> 762
> 6353
> 6443
> 3309
> -
> -
> -
> -
> -
> -
> -
> -
> 294
> 867
> 859
> 7695
> 97
> 49
> -
> -
> -
> -
>
> ---------------
> end log file
>
>
> how can I add all the numbers without having those dashes causing a problem?
>
> cheers,
> Liam
>
>
>
>