 <p>Here's an example, to give you an idea:</p> <pre><code>function recursiveKeyTargeting($array, $target_key, $element_to_add) { foreach($array AS $arr) { if(is_array($arr['key'])) { recursiveKeyTargeting($array['key'], $target_key, $element_to_add); } else if($arr['key'] == $target_key) { $arr[] = $element_to_add; break; } } } </code></pre>