Actions

PHP: Delete an item from an array

From zen2

Revision as of 03:20, 26 October 2008 by 118.93.27.40 (talk) (New page: <pre> /** * This function will remove all the specified values from an array and return the final array. * Arguments : The first argument is the array that should be edited * ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 /**
 * This function will remove all the specified values from an array and return the final array.
 * Arguments :    The first argument is the array that should be edited
 *                The arguments after the first argument is a list of values that must be removed.
 * Example : array_remove_value($arr,"one","two","three");
 * Return : The function will return an array after deleting the said values
 */

		function array_remove_value() {
			$args = func_get_args();
			$arr = $args[0];
			$values = array_slice($args,1);
			foreach($arr as $k=>$v) {
				if(in_array($v, $values))
				unset($arr[$k]);
			}
			return $arr;
		}