Hello,
After reading in a lot of random data from a database and storing it all in an array. The way it looks is something like:
Dealer number, Dealer name, Car Color, Body Type, etc etc etc
There are a variable number of different unique dealer numbers, but many of the cars belong to the same dealers. Example
Car 1: 6145, Foo Auto, Red, Sedan, etc etc etc
Car 2: 4538, Bar Auto, Blue, Truck, etc etc etc
Car 3: 6145, Foo Auto, Black, Van, etc etc etc
Car 4: 5840, Hello World, White, Sedan, etc etc etc
Car 5: 4538, Bar Auto, Yellow, Submarine, etc etc etc
Those 5 cars are all in an array. The array elements are just bar delimited string (6145|Foo Auto|Red|Sedan|etc etc etc).
What I need to do is parse this data in such a way where I have all the cars for each dealer in a neat manner. Here is where my questions come in.
1: The only way I could think of doing it was an associative array where the key is the dealer number, and the value associated with that key is an array of cars. Obvious question here is if there is a simpler way, I can't think of one.
2: Trying to put my idea into code didn't go too well for me...
$formatData = array();
foreach ($allCars as $_count => $_car) {
$flag = 0;
foreach ($formatData as $key => $value)
if ($_car['DealerNum'] == $key)
$flag = 1;
if (!$flag) //key is not in the array
I couldn't really get much farther than that though I don't even think that much is right.
Any help would be greatly appreciated, thank you very much.