Created
March 20, 2012 12:34
-
-
Save mikaelkundert/2134718 to your computer and use it in GitHub Desktop.
Function which pushes an array element after specified key. Note that array is not catched as reference. You need to re-set your array when using this function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function array_push_after_key($array, $key, $var) { | |
$new_array = array(); | |
foreach ($array as $k => $v) { | |
$new_array[$k] = $v; | |
if ($k === $key) { | |
foreach ($var => $kk => $vv) { | |
$new_array[$kk] = $vv; | |
} | |
break; | |
} | |
} | |
return $new_array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment