Voting

: min(two, eight)?
(Example: nine)

The Note You're Voting On

aexchecker at yahoo dot com
17 years ago
<?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 <[email protected]>
* @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)
);
}
?>

<< Back to user notes page

To Top