I have an array containing possible values:
$auto_types = array(CHEVY, FORD, DODGE);
And I have have arrays that contain those values:
$my_cars = array(
array("make" => "FORD", model => "Thunderbird", "year" => 1983),
array("make" => "FORD", model => "Mustang", "year" => 1971),
array("make" => "CHEVY", model => "Impala", "year" => 1995),
array("make" => "DODGE", model => "Charger", "year" => 2015),
array("make" => "CHEVY", model => "Corvette", "year" => 2011),
array("make" => "CHEVY", model => "Camaro", "year" => 2012)
)
I want to return a list that supplies a header of each make, and then sorts each car by the Make. So the output would be:
CHEVY:
1995 Impala
2012 Corvette
2011 Camaro
DODGE:
2015 Charger
FORD:
1971 Mustang
1983 Thunderbird
I know I can run a foreach()
loop and sort by make, but the key here is that I want a header for each make, instead of listing it for every car. Anyone have a good way to do this? -- Not sure if the first array is even needed, but it seemed like a good idea to create it at the time.