rotate an array values by using index in PHP


// here $array is the one you want to rotate
function array_pop_index($array, $index)
{
if( ( $index < count($array) ) && ($index >= 0))
{
$value_at_the_index = $array[$index];
$_2d_array = array_chunk($array, ($index+1) );
$resulting_array = array();

for($i=0; $i < count($_2d_array); $i++)
{
if($i==0)
{
array_pop($_2d_array[0]);
}

$resulting_array=array_merge( $resulting_array, $_2d_array[$i] );
}

return $resulting_array;
}
else
{
return;
}
}
?>

Comments

Popular posts from this blog

MRTG configurations

ADSL configuration on Cisco router