note 78257 added to function.array-slice
| From: | aexchecker at yahoo dot com | Date: | Thu, 04 Oct 2007 15:39:47 +0000 |
| Subject: | note 78257 added to function.array-slice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-131083@lists.php.net to get a copy of this message | ||
<?php
/**
* @desc
* Combines two arrays by inserting one into the other at a given position then
* returns the result.
*
* @since 2007/10/04
* @version v0.7 2007/10/04 18:47:52
* @author AexChecker <AexChecker@yahoo.com>
* @param array $source
* @param array $destination
* @param int [optional] $offset
* @param int [optional] $length
* @return array
*/
function array_insert($source, $destination, $offset = NULL, $length = NULL) {
if (!is_array($source) || empty($source)) {
if (is_array($destination) && !empty($destination)) {
return $destination;
}
return array();
}
if (is_null($offset)) {
return array_merge($destination, $source);
}
$offset = var2int($offset);
if (is_null($length)) {
if ($offset === 0) {
return array_merge($source, array_slice($destination, 1));
}
if ($offset === -1) {
return array_merge(array_slice($destination, 0, -1), $source);
}
return array_merge(
array_slice($destination, 0, $offset),
$source,
array_slice($destination, ++$offset)
);
}
if ($offset === 0) {
return array_merge($source, array_slice($destination, $length));
}
$destination_count = count($destination);
$length = var2int($length);
if ($offset > 0) {
if ($destination_count - $offset < 1) {
return array_merge($destination, $source);
}
} else{
if (($t = $destination_count + $offset) < 1) {
return array_merge($source, $destination);
}
$offset = $t;
}
if ($length > 0) {
$length+= $offset;
} elseif ($length < 0 && !($length * -1 < $destination_count)) {
return $source;
} else {
$length = $offset;
}
return array_merge(
array_slice($destination, 0, $offset),
$source,
array_slice($destination, $length)
);
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 77.122.37.248
----
Manual Page -- http://www.php.net/manual/en/function.array-slice.php
Edit -- https://master.php.net/note/edit/78257
Del: integrated -- https://master.php.net/note/delete/78257/integrated
Del: useless -- https://master.php.net/note/delete/78257/useless
Del: bad code -- https://master.php.net/note/delete/78257/bad+code
Del: spam -- https://master.php.net/note/delete/78257/spam
Del: non-english -- https://master.php.net/note/delete/78257/non-english
Del: in docs -- https://master.php.net/note/delete/78257/in+docs
Del: other reasons-- https://master.php.net/note/delete/78257
Reject -- https://master.php.net/note/reject/78257
Search -- https://master.php.net/manage/user-notes.php