Mega Code Archive

 
Categories / Php / Data Type
 

Getting and Displaying Counts of Array Values

<html> <head> <script type="text/javascript"> </script> </head> <body> <?php   $countries = array( 'USA' => 'English', 'Spain' => 'Spanish',                       'France' => 'French', 'Argentina' => 'Spanish');   $languages = array_values($countries);   $language_count = array();   foreach($languages as $language)     if(!isset($language_count[$language]))       $language_count[$language] = 1;     else       $language_count[$language]++; ?>   <table>     <tbody>       <tr><th>Language</th><th>Number<br />of<br />Countries</th></tr> <?php   foreach($language_count as $language => $number)     print "<tr><td>$language</td><td>$number</td></tr>\n"; ?>     </tbody>   </table> </body> </html>