note 103437 added to function.array-splice

From: Date: Wed, 13 Apr 2011 15:10:58 +0000
Subject: note 103437 added to function.array-splice
Groups: php.notes 
Request: Send a blank email to php-notes+get-178796@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: $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] ---- Server IP: 69.147.83.197 Probable Submitter: 207.242.44.6 ---- Manual Page -- http://www.php.net/manual/en/function.array-splice.php Edit -- https://master.php.net/note/edit/103437 Del: integrated -- https://master.php.net/note/delete/103437/integrated Del: useless -- https://master.php.net/note/delete/103437/useless Del: bad code -- https://master.php.net/note/delete/103437/bad+code Del: spam -- https://master.php.net/note/delete/103437/spam Del: non-english -- https://master.php.net/note/delete/103437/non-english Del: in docs -- https://master.php.net/note/delete/103437/in+docs Del: other reasons-- https://master.php.net/note/delete/103437 Reject -- https://master.php.net/note/reject/103437 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178796) next »