Reputation: 18369
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.
Upvotes: 2
Views: 189
Reputation: 4258
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
Upvotes: 7