I want to make an key pair array in foreach loop in php. In my foreach loop i have city name and user name. I want to add all users for same city in array.
Ex [{city=>'pune',users=>("a","b","c","d")},{'city=>nk',users=>("e","b","c","f")}] or any other array format.
foreach ($studsInfo as $value) {
$studId = "".$value['_id'];
$indDetail = $industryM->getAllIndustries($studId);
$indusArray['industry'] = iterator_to_array($indDetail);
$city = $value['city'];
$name = $value['firstname'];
}
How could I add all name in array for same city.
Thankx in advance, Any suggestion and editing are welcome