[ create a new paste ] login | about

Link: http://codepad.org/LrcPQoTe    [ raw code | output | fork ]

Indev - PHP, pasted on Jun 6:
<?
$arr[0] = 'test';
$arr[2] = 'test2';
$arr[3] = 'test3';
$bool = false;
while ($bool != true)
{
$prev_key = 0;
foreach ($arr as $key => $val)
{
if (($key - 1) > $prev_key)
{
$arr[$prev_key + ($key - $prev_key - 1)] = $val;
unset($arr[$key]);
$bool = false;
break;
}
$prev_key = $key;
$bool = true;
}
}
var_dump($arr);
?>


Output:
1
2
3
4
5
6
7
8
array(3) {
  [0]=>
  string(4) "test"
  [1]=>
  string(5) "test2"
  [2]=>
  string(5) "test3"
}


Create a new paste based on this one


Comments: