taking tally of values in array

sagarsspace

New Member
I have an array:\[code\]$record = array(Won,Lost,Won,Won,Lost);\[/code\]I want to count the number of wins and losses in the array.So everytime it finds "Won" in the array, do a $won++, and the same for loss, $loss++I want to print out the record after that is completed.\[code\]print $won.' - '.$lost;\[/code\]I think I figured it out, revisions to make this more efficient, will be appreciated.\[code\]<?php$won = 0;$lost = 0;foreach ($record as $i => $value) { if($value =http://stackoverflow.com/questions/3869019/="Won") { $won++; } elseif($value =http://stackoverflow.com/questions/3869019/="Lost") { $lost++; }}?>\[/code\]
 
Back
Top