Skip to content

Instantly share code, notes, and snippets.

@necenzurat
Created March 26, 2014 18:39
Show Gist options
  • Save necenzurat/9790239 to your computer and use it in GitHub Desktop.
Save necenzurat/9790239 to your computer and use it in GitHub Desktop.
<?php
$array = array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15");
echo "<pre>";
function AddElementToArrayAfter($array = "", $element = "", $after = "") {
$count = 0;
foreach ($array as $k => $v)
{
// insert new object
if ($count)
{
if ($k % $after == 1) {
$return[$k] = $element;
}
}
// insert old object
$return[$k] = $v;
$count++;
}
return $return;
}
$a = AddElementToArrayAfter($array, 'BREAK', 4);
print_r($a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment