I have the following arrays:
Array (db_values)
(
[0] => Array
(
[system_name] => object_car_brand
[value] => Alfa Romeo
[id] => 136
)
[1] => Array
(
[system_name] => object_car_model
[value] => Spider
[id] => 137
)
)
Array (db_attributes)
(
[0] => Array
(
[id] => 105
[system_name] => object_car_brand
)
[1] => Array
(
[id] => 106
[system_name] => object_car_model
)
)
I combine these two using the following code:
foreach($db_attributes as $db_attribute){
foreach($db_values as $db_value){
if($db_value["system_name"] === $db_attribute["system_name"]){
$update[$db_attribute["id"]] = $db_value["value"];
}
}
}
I do not think that this is the most resource friendly way of doing it, is there a better way?
RecursiveArrayIterator
class. (php.net/manual/en/class.recursivearrayiterator.php). I never used it, so, I can't help much. – Ismael Miguel Nov 20 '14 at 13:52