note 80219 added to function.array-filter

From: Date: Fri, 04 Jan 2008 14:47:58 +0000
Subject: note 80219 added to function.array-filter
Groups: php.notes 
Request: Send a blank email to php-notes+get-134769@lists.php.net to get a copy of this message
Be careful with this function as it preserves array indexes after applying the filter: <?php function f( $item ){ return $item < 50; } print_r( array_filter(array( 10, 100, 20 ),"f") ); /* OUTPUT Array ( [0] => 10 [2] => 20 )*/ ?> You can easily reassign indexes like this: <?php function f( $item ){ return $item < 50; } print_r( array_values(array_filter(array( 10, 100, 20 ),"f")) ); /* OUTPUT Array ( [0] => 10 [1] => 20 )*/ ?> ---- Server IP: 130.206.1.5 Probable Submitter: 83.42.102.150 ---- Manual Page -- http://www.php.net/manual/en/function.array-filter.php Edit -- https://master.php.net/note/edit/80219 Del: integrated -- https://master.php.net/note/delete/80219/integrated Del: useless -- https://master.php.net/note/delete/80219/useless Del: bad code -- https://master.php.net/note/delete/80219/bad+code Del: spam -- https://master.php.net/note/delete/80219/spam Del: non-english -- https://master.php.net/note/delete/80219/non-english Del: in docs -- https://master.php.net/note/delete/80219/in+docs Del: other reasons-- https://master.php.net/note/delete/80219 Reject -- https://master.php.net/note/reject/80219 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#134769) next »