Mega Code Archive

 
Categories / Php / Data Type
 

Loops through an indexed array of fruit names and creates a new array with the count of each fruit name

<?php $fruits = array('apple', 'orange', 'orange'); $fruit_count = array(); foreach ($fruits as $i=>$fruit) {   @$fruit_count[$fruit]++; } asort($fruit_count); foreach ($fruit_count as $fruit=>$count) {   echo "$fruit = $count\n"; } ?>