views:

139

answers:

1
+2  Q: 

PHP Array Help

I have an array which is a list of domains, I want to print all of the items in the array except the one which contains $x. $x is variable so basically it never prints the array item when it contains $x. Can anyone help me? :)

+7  A: 

Darkey's answer is correct assuming you don't want to print array values that equal $x - but if you don't wish to print those that "contain" $x, try:

foreach ($array as $key => $value) {
    if (strpos($value, $x) === false) {
         print($value);
    }
}

If $x = stack, then entries such as "stackoverflow.com" and "getstacked.org" would be excluded

iAn
Thank you this was exactly what I was looking for.
zuk1