note 103437 modified in function.array-splice by danbrown
| From: | danbrown@php.net | Date: | Wed, 13 Apr 2011 15:26:28 +0000 |
| Subject: | note 103437 modified in function.array-splice by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-178797@lists.php.net to get a copy of this message | ||
Unexpected behavior if you're trying to use array_splice to truncate an array. For example:
<?php $aOut = array_splice($aIn, 300); ?>
If sizeof($aIn) < 300, the entire $aOut array gets wiped out! The extra conditional is needed to
ensure this doesn't happen:
<?php
if (sizeof($aIn) > MAX_WINDOW_COUNT) {
$aOut = array_splice($aIn, MAX_WINDOW_COUNT);
}
?>
[PHP 5.3.6]
--was--
Unexpected behavior if you're trying to use array_splice to truncate an array. For example:
$aOut = array_splice($aIn, 300);
If sizeof($aIn) < 300, the entire $aOut array gets wiped out! The extra conditional is needed to
ensure this doesn't happen:
if (sizeof($aIn) > MAX_WINDOW_COUNT) {
$aOut = array_splice($aIn, MAX_WINDOW_COUNT);
}
[PHP 5.3.6]
http://php.net/manual/en/function.array-splice.php