[SOLVED] Delete from an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

[SOLVED] Delete from an array

Post by Stryks »

I always get myself into trouble asking these questions, but anyhow ...

Is there any function for deleting an array from an array?

Like ...

Code: Select all

$arr1 = array("apple", "pear", "orange", "small one eyed dog");
$arr2 = array("orange", "apple");

print_r(array_blah($arr1, $arr2));
... giving output of something like ...
array([0]=>"pear" [1]=>"small one eyed dog")
Failing a function like this, I guess I'll just do an array_search and unset any matches, but I cant find a function or an alternate clean way of doing this, and though I've searched, I havent found anything much.

Cheers
Last edited by Stryks on Thu Aug 09, 2007 7:45 am, edited 1 time in total.
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Post by Stryks »

See .... :oops:

array_diff seems to do the job quite neatly.

Cheers anyway all 8)
Post Reply