Created
November 26, 2014 22:07
-
-
Save gabesullice/47472815fac429a19df1 to your computer and use it in GitHub Desktop.
Insert 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
<?php | |
function my_array_insert(&$array, $insert, $key_before) { | |
$offset = 1; | |
while (key($array) != $key_before) { | |
next($array); | |
$offset++; | |
} | |
$array_before = array_slice($array, 0, $offset, TRUE); | |
$array_after = array_slice($array, $offset, NULL, TRUE); | |
$array = array_merge($array_before, $insert, $array_after); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment