Jump to content

!not operator doesn't seem to be doing what i expect


c_shelswell

Recommended Posts

Hi i have a very simple for each statment spitting out some stuff on my page. One of the array id's is "username" and i'm after it missing that one out but doing this rest

I thought this would work
[code]
foreach ($details as $key => $value)
{
if (!(($i + 1)% 2))
{
if (!$key == 'username')
{
$head = explode("_", $key);
echo "<span class='textFieldReg'>".ucfirst($head[0]." ".$head[1]).":</span> \n";
echo "<input type='text' name='$key' value='$value' class='myInputReg'/><br />\n";
}
}
$i++;
}
[/code]
it's the "!$key == 'username'" bit i mean if i take away the "!" is just gives me the username field but if i put in the "!" it doesn't give me anything.

Can't quite understand.
[quote author=HuggieBear link=topic=121777.msg501324#msg501324 date=1168439272]
It should be...

[code=php:0]if ($key != 'username'){[/code]

Not ...

[code=php:0]if (!$key == 'username'){[/code]

Regards
Huggie
[/quote]
Or... we could really throw a monkey wrench in it and check it this way:
[code]
<?php
if (!($key == 'username'))
?>
[/code]
[quote author=HuggieBear link=topic=121777.msg501334#msg501334 date=1168439862]
I love a good Monkey Wrench every now and again :)

Huggie
[/quote]

LOL... yes, same here. I was basically just trying to point out that all the '!' operator does is negates the associated value. So, without the parenthetical, it's trying to negate $key alone. If you simply add the parenthesis around your comparison operation, it's actually negating the entire comparison process, therefore returning the value you're after.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.