Return to Snippet

Revision: 31416
at September 4, 2010 09:35 by DADU


Initial Code
/* EXAMPLE

print_r(array_remove(array('d','a','d','u'),'d',true));

*/

function array_remove($array,$value,$remove_all=false) {
	
	$keys = array_keys($array,$value);
	
	switch($remove_all):
	
		case false:
			$key = (count($keys) >= 1 ? $keys[0] : NULL);
			unset($array[$key]);
			break;
			
		case true:
			foreach($keys as $key) unset($array[$key]);
			break;
		
	endswitch;
	
	return $array;
}

Initial URL

                                

Initial Description
This PHP code snippet searches a value in an array. Depending on use, one or all matching values and their belonged keys are removed.

Initial Title
array remove value

Initial Tags
array

Initial Language
PHP