Page 1 of 1

need help filtering array

Posted: Thu Feb 11, 2010 9:08 pm
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.

Re: need help filtering array

Posted: Fri Feb 12, 2010 5:36 am
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.

Re: need help filtering array

Posted: Fri Feb 12, 2010 6:52 am
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!