note 111421 modified in function.array-slice by danbrown
| From: | danbrown@php.net | Date: | Mon, 04 Mar 2013 18:04:03 +0000 |
| Subject: | note 111421 modified in function.array-slice by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193876@lists.php.net to get a copy of this message | ||
Rotate an associative array to start with a specific key
<?php
function rotate_array($array, $key) {
$keys = array_keys($array);
$values = array_values($array);
$offset = array_search($key, $keys);
$keys = array_merge(array_splice($keys, $offset), $keys);
$values = array_merge(array_splice($values, $offset), $values);
return array_combine($keys, $values);
}
?>
--was--
//Rotate an associative array to start with a specific key
function rotate_array($array, $key) {
$keys = array_keys($array);
$values = array_values($array);
$offset = array_search($key, $keys);
$keys = array_merge(array_splice($keys, $offset), $keys);
$values = array_merge(array_splice($values, $offset), $values);
return array_combine($keys, $values);
}
http://php.net/manual/en/function.array-slice.php