This has to do with counting in PHP, and there are numerous questions and examples of that, but none that I can find of what I need to do: count the occurrences of the value of a variable and output that count as its own variable.
The values I want to count and output as variables are each of the 50 state two letter abbreviations, i.e. AL, AK AR...; they are contained in $state.
What's the most efficient way to count the number of occurrences of each state and output each as a variable, i.e. $AL_total and $AK_total and $AR_total, etc.?
// I have data in the format
// firstname\n lastname \naddress \ncity \nstate \nzip
// This explode strings into array
foreach($values as $val) {
$valuearray = explode("\n", implode($val));
// This assigns variables that are used to echo each field of data
$firstname = $valuearray[0];
$lastname = $valuearray[1];
$address = $valuearray[2];
$city = $valuearray[3];
$state = $valuearray[4];
$zip = $valuearray[5];
// count $state and output as $AL_total , $AK_total , $AR_total , etc.
// And then...
echo $AL_total;
etc....