Thursday, August 2, 2018

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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...