I'm using the following piece of code to count the number of locations
from a table:
$result = mysqli_query($conn,"SELECT location FROM table ORDER BY location");
$aloc_list = array();
while ($row = mysqli_fetch_array($result))
{$aloc_list[] = $row['location'];
}
print_r(array_count_values($aloc_list));
Which gives me the following array:
Array
(
[CANADA] => 106
[USA] => 547
[MEXICO] => 93
[GREAT_BRITAIN] => 111
[EASTERN_EUROPE] => 227
[RUSSIA] => 405
[CHINA] => 341
[INDIA] => 253
)
I have tried to 'extract' the array values and put them in a variable but nothing seems to work:
$canada = $aloc_list[0];
$canada = $aloc_list['CANADA'];
$canada = $aloc_list[0]['CANADA'];
$canada = $aloc_list[0];
I want to end up with a variable called $canada
equal to 106, a variable called $usa
equal to 547, etc.
How do I accomplish this?