need help filtering 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
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

need help filtering array

Post by someguyhere »

I have an array that is generated on the fly, and in the event that it adds data from a google domain, I want to unset that item from the array.

Here is an example of an array that the app created:

Code: Select all

Array
(
    [0] => http://www.tradertots.com/
    [1] => http://news.google.com/news?q=children& ... CB0QsQQwAA">News results for children
    [2] => http://www.mykidscloset.com/
    [3] => http://www.habitat.org/env/restores.aspx
)
 
So basically, if any of the urls contain google.com, I want them unset.
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: need help filtering array

Post by JakeJ »

Why not test it before it's added in to the array and skip adding it. Otherwise you're going to have to loop through the array all the time and use the unset command then. It's more efficient to prevent it's addition to the array.
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: need help filtering array

Post by someguyhere »

You know, that thought had crossed my mind but for some reason, I thought it might be easier to do it after the fact. It turns out that doing it beforehand is easier, and probably even makes the script run faster.

Thanks!
Post Reply