Skip to content

Instantly share code, notes, and snippets.

@gabesullice
Created November 26, 2014 22:07
Show Gist options
  • Save gabesullice/47472815fac429a19df1 to your computer and use it in GitHub Desktop.
Save gabesullice/47472815fac429a19df1 to your computer and use it in GitHub Desktop.
Insert function
<?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