I am iterating through an array of arrays that contains sales data returning from a MySQL query:
$result = mysql_query("select salespersonId,grossProfit FROM sales");
foreach ($result as $line) {
$salespersonId = $line['salespersonId'];
$grossProfit = $line['grossProfit'];
}
I want to push the line into separate arrays per salespersonId (so that the 10 lines belonging to salespersonId 1 are in one array, and the 10 lines belonging to salespersonId 2 are in a different array) but I cannot seem to figure out how to do this. I've tried things like:
array_push(${'data'.$salespersonId},$line);
to no avail. I feel like I might need an associative array of arrays, but you can't array_push into associative arrays. What am I missing?