note 97461 added to function.array-splice
| From: | php dot net at webdevelopers dot cz | Date: | Wed, 21 Apr 2010 11:32:15 +0000 |
| Subject: | note 97461 added to function.array-splice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-168469@lists.php.net to get a copy of this message | ||
Simple array_ksplice - version of array_splice preserving the keys:
/**
* array_splice does not preserve the replacement keys.
*
* Example:
* $pos=(int) array_search('text/html', array_keys($list[$id]['data']));
* array_ksplice($list[$id]['data'], $pos, 0, array('text/xml' =>
'<b>testX</b>'));
*
* @access public
* @param array &$input The input array
* @param int $offset The sequence will start at that offset in the array.
* @param int $length How many elements will be removed
* @param array $replacement The removed elements are replaced with elements from this array.
* @return void
*/
function array_ksplice(&$input, $offset, $length, $replacement) {
$input=array_merge(
array_slice($input, 0, $offset, true),
$replacement,
array_slice($input, $offset + $length, count($input) - $offset - $length, true),
$replacement // In case that the tail contains the same keys as $replacement do replace
replaced values
);
}
----
Server IP: 147.32.160.17
Probable Submitter: 90.178.106.75
----
Manual Page -- http://www.php.net/manual/en/function.array-splice.php
Edit -- https://master.php.net/note/edit/97461
Del: integrated -- https://master.php.net/note/delete/97461/integrated
Del: useless -- https://master.php.net/note/delete/97461/useless
Del: bad code -- https://master.php.net/note/delete/97461/bad+code
Del: spam -- https://master.php.net/note/delete/97461/spam
Del: non-english -- https://master.php.net/note/delete/97461/non-english
Del: in docs -- https://master.php.net/note/delete/97461/in+docs
Del: other reasons-- https://master.php.net/note/delete/97461
Reject -- https://master.php.net/note/reject/97461
Search -- https://master.php.net/manage/user-notes.php