note 98345 added to language.types.array

From: Date: Wed, 09 Jun 2010 23:28:58 +0000
Subject: note 98345 added to language.types.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-170005@lists.php.net to get a copy of this message
I couldn't find a way to Trim an array in PHP so i wrote this little function that seemed to do the trick. It will trim the array down to a specified size <?php //Utility Function to Trim Array function trim_array(array $array,$int){ $newArray = array(); for($i=0; $i<$int; $i++){ array_push($newArray,$array[$i]); } return (array)$newArray; } ?> Example: var_dump($treatList); array(3) { ["id"]=> string(3) "476" ["categoryID"]=> string(2) "49" ["title"]=> string(55) "80% off Sidewalk Crawling Classes from Urban Adventures" $treatList = trim_array($listist,2); Will result in: var_dump($treatList); array(2) { ["id"]=> string(3) "476" ["categoryID"]=> string(2) "49" ---- Server IP: 69.147.83.197 Probable Submitter: 173.196.139.66 ---- Manual Page -- http://www.php.net/manual/en/language.types.array.php Edit -- https://master.php.net/note/edit/98345 Del: integrated -- https://master.php.net/note/delete/98345/integrated Del: useless -- https://master.php.net/note/delete/98345/useless Del: bad code -- https://master.php.net/note/delete/98345/bad+code Del: spam -- https://master.php.net/note/delete/98345/spam Del: non-english -- https://master.php.net/note/delete/98345/non-english Del: in docs -- https://master.php.net/note/delete/98345/in+docs Del: other reasons-- https://master.php.net/note/delete/98345 Reject -- https://master.php.net/note/reject/98345 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170005) next »