note 33517 deleted from function.array-filter by cmb

From: Date: Sun, 06 Oct 2019 08:14:21 +0000
Subject: note 33517 deleted from function.array-filter by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212500@lists.php.net to get a copy of this message
Note Submitter: redshift at pandora dot be ---- Hi all, Here's a function that will look trough an array, and removes the array member when the search string is found. <?php function array_clean ($input, $delete = false, $caseSensitive = false) { $i = 0; while($i < count($input)) { if($delete) { if($caseSensitive) { if(!strstr($input[$i] ,$delete)) { $return[] = $input[$i]; } } else { if(!stristr($input[$i], $delete)) { $return[] = $input[$i]; } } } else { if(!empty($input[$i])) { $return[] = $input[$i]; } } $i++; } return $return; } ?> array array_clean(array input [, string needle [, boolean case sensitive]]) if needle is left empty, the function will delete the array members that have no value (this means if it's empty). NOTE: It rebuilds the array from scratch, so keys begin with 0, like you would create a new array. Example: $array = array("John", "Doe", "Macy"); $array = array_clean($array, "doe", false); print_r($array); would return: array ( [0] => John [1] => Macy ) Hopes this helps someone :-)

« previous php.notes (#212500) next »