Skip to content

Instantly share code, notes, and snippets.

@albertofem
Created July 2, 2012 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albertofem/3035119 to your computer and use it in GitHub Desktop.
Save albertofem/3035119 to your computer and use it in GitHub Desktop.
Complexity Algorithm
<?php
$test = array(
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
);
$test2 = array(
2 => "mine-2",
4 => "mine-4",
7 => "mine-7"
);
function array_shift_next(&$array, $index, $limit = null)
{
for($i=count($array)-1; $i>$index-2; $i--)
{
if($i+1 > $limit)
continue;
$array[$i+1] = $array[$i];
}
$array[$index-1] = null;
}
var_dump($test);
foreach($test2 as $key => $value)
{
array_shift_next($test, $key, 8);
}
foreach($test2 as $key => $value)
{
$test[$key-1] = $value;
}
var_dump($test);
// complexity O(m(n+1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment