Have I missed something? array_rotate() ????
Posted: Mon May 02, 2005 9:40 am
Hi,
Maybe I'm just being plain crazy or something but I swear I have used a function before called something to the effect of array_rotate()....
As in, it rotates the array contents (take the first element off and puts it on the end). I can't find it now so I'm doing this...
Please tell me if there IS a PHP function for this (mine only does numeric indexes (but I could change it))
I am having "one of those days" 
Maybe I'm just being plain crazy or something but I swear I have used a function before called something to the effect of array_rotate()....
As in, it rotates the array contents (take the first element off and puts it on the end). I can't find it now so I'm doing this...
Please tell me if there IS a PHP function for this (mine only does numeric indexes (but I could change it))
Code: Select all
function array_rotate($array, $rev=false) {
if ($rev) {
array_reverse($array); //Back-to-front
} //End if
$first = $array[0]; //Store first value
array_shift($array); //Take off first value
array_push($array, $first); //Put first back on the end
if ($rev) {
array_reverse($array); //Back-the-right-way
} //End if
return $array;
} //End function