Can someone please explain what is going on in the code below? I understand it until the $categories[$category][] = $row['agency']; line.
$categories = array();
while ($row = mysqli_fetch_array($result))
{
$category = $row['category'];
$categories[$category][] = $row['agency'];
}
The results you are getting from your database are likely:
Category Agency
The $category = $row[‘Category’]; gets the value from the result for the Category (i.e Security, Government, Misc).
After that the Categories array is added to. It is an array of arrays. So it stores for each category an array of agencies.