PHP: 'rotate' an array?
Most of the current answers are correct, but only if you don't care about your indices:
$arr = array('foo' => 'bar', 'baz' => 'qux', 'wibble' => 'wobble');array_push($arr, array_shift($arr));print_r($arr);
Output:
Array( [baz] => qux [wibble] => wobble [0] => bar)
To preserve your indices you can do something like:
$arr = array('foo' => 'bar', 'baz' => 'qux', 'wibble' => 'wobble');$keys = array_keys($arr);$val = $arr[$keys[0]];unset($arr[$keys[0]]);$arr[$keys[0]] = $val;print_r($arr);
Output:
Array( [baz] => qux [wibble] => wobble [foo] => bar)
Perhaps someone can do the rotation more succinctly than my four-line method, but this works anyway.