c_shelswell Posted January 10, 2007 Share Posted January 10, 2007 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 Link to comment https://forums.phpfreaks.com/topic/33589-not-operator-doesnt-seem-to-be-doing-what-i-expect/ Share on other sites More sharing options...
HuggieBear Posted January 10, 2007 Share Posted January 10, 2007 It should be...[code=php:0]if ($key != 'username'){[/code] Not ...[code=php:0]if (!$key == 'username'){[/code] RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/33589-not-operator-doesnt-seem-to-be-doing-what-i-expect/#findComment-157344 Share on other sites More sharing options...
c_shelswell Posted January 10, 2007 Author Share Posted January 10, 2007 easy - fantastic thanks very much Quote Link to comment https://forums.phpfreaks.com/topic/33589-not-operator-doesnt-seem-to-be-doing-what-i-expect/#findComment-157345 Share on other sites More sharing options...
obsidian Posted January 10, 2007 Share Posted January 10, 2007 [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] RegardsHuggie[/quote]Or... we could really throw a monkey wrench in it and check it this way:[code]<?phpif (!($key == 'username'))?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33589-not-operator-doesnt-seem-to-be-doing-what-i-expect/#findComment-157348 Share on other sites More sharing options...
HuggieBear Posted January 10, 2007 Share Posted January 10, 2007 I love a good Monkey Wrench every now and again :)Huggie Quote Link to comment https://forums.phpfreaks.com/topic/33589-not-operator-doesnt-seem-to-be-doing-what-i-expect/#findComment-157354 Share on other sites More sharing options...
obsidian Posted January 10, 2007 Share Posted January 10, 2007 [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. Quote Link to comment https://forums.phpfreaks.com/topic/33589-not-operator-doesnt-seem-to-be-doing-what-i-expect/#findComment-157359 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.