Thursday 31 March 2016

PHP Removing elements from an array




I am new to PHP and I need a function that enables me to remove an item from an array.



So far I have:



 $ab = milk
$ba = apple
$ca = bread


array($ab, $ba, $ca).


Is there a function or method available to delete $ba from the list?



      I.e  if (condition)==true

array_delete ($ab): ($ab, $ba, $ca)



Obviously the above does not work, or exist, but I am looking for something like it that does exist.



Any help would be huugely appreciated!



Thanks


Answer



you can try this:



$ab = milk;
$ba = apple;

$ca = bread;

$arr=array($ab, $ba, $ca);
if (in_array($ba, $arr))
{
unset($ba);
}


hope this may help you..



No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...