Actions

Difference between revisions of "PHP: Delete an item from an array"

From zen2

(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 * ...)
 
m (1 revision)
 
(No difference)

Latest revision as of 08:45, 25 July 2013

 /**
 * 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;
		}