[SOLVED] Array Woes
Posted: Sun Jun 26, 2005 8:57 pm
Ok, I am having a problem with array data, and I think I'm just making it harder than it really is. I have an array with keys and values and valuevalues within each key.
I'm pulling this data from a mysql table and then creating the array based on the row data (ie :
For instance, let's say that this is my array :
$MyArray
notice how 1 and 2 have the exact same vehicle_type, and manufacturer. What I want to do is loop through the array, and find the vehicle type. And while the vehicle type is set to Car, loop search for Reoccuring Manufacturers, and then combine the years together.
So, the resulting array would look something like this :
See what I mean? I've busted my damn brain on trying to figure this out. Can anyone help out? Thanks.
Again, what i'm trying to accomplish is loop through the numerical index of the array (0,1,2,3,...). While i'm looping through the index, I want to say "Ok, if the next 5 indexes all have the EXACT SAME vehicle_type, then search to see if the MANUFACTURER is the EXACT same. If we Find duplicate manufacturers, then combine all their YEAR values into one big value seperated by commas, otherwise, continue with the script.
I'm pulling this data from a mysql table and then creating the array based on the row data (ie :
Code: Select all
//....
while($row=mysql_fetch_assoc($sql) {
$MyArray[] = $row;
}
//....$MyArray
Code: Select all
Array
(
ї0] => Array
(
їvehicle_type] => truck
їmanufacturer] => Toyota
їyear] => 2004
)
ї1] => Array
(
їvehicle_type] => Car
їmanufacturer] => Nissan
їyear] => 1998
)
ї2] => Array
(
їvehicle_type] => Car
їmanufacturer] => Nissan
їyear] => 2000
)
ї3] => Array
(
їvehicle_type] => Car
їmanufacturer] => Ford
їyear] => 2005
)
)So, the resulting array would look something like this :
Code: Select all
Array
(
ї0] => Array
(
їvehicle_type] => truck
їmanufacturer] => Toyota
їyear] => 2004
)
ї1] => Array
(
їvehicle_type] => Car
їmanufacturer] => Nissan
їyear] => 1998, 2000
)
ї2] => Array
(
їvehicle_type] => Car
їmanufacturer] => Ford
їyear] => 2005
)
)See what I mean? I've busted my damn brain on trying to figure this out. Can anyone help out? Thanks.
Again, what i'm trying to accomplish is loop through the numerical index of the array (0,1,2,3,...). While i'm looping through the index, I want to say "Ok, if the next 5 indexes all have the EXACT SAME vehicle_type, then search to see if the MANUFACTURER is the EXACT same. If we Find duplicate manufacturers, then combine all their YEAR values into one big value seperated by commas, otherwise, continue with the script.