Combining two arrays using nested foreach loops
I have made the assumption that there is a 1:1 relationships between the $attributes and $values array elements. With that I mean the array key in the $attributes array corresponds with an entry in $values array.

If that is the case it can be reduced to one foreach loop by using the key from the attributes array:

$combined = []; // Make sure the $combined array exists.

foreach($attributes as $key =&gt; $attribute) {

    // First check if the array key exists and that the 'system_name' is the same
    if(array_key_exists($key, $values) &amp;&amp; $attribute['system_name'] == $values[$key]['system_name']) {

        $combined[$attribute['id']] = $values[$key]['value'];

    }

}


This should produce the following array with the data you have provided:

Array(combined)
(
    [106] =&gt; 'Alfa Romeo' 
)


If my assumption is incorrect, then just ignore my answer.