Jump to content

confused about !==


cumpstey

Recommended Posts

I want a session variable, 'init', to be updated only when another variable, 'initial' is not blank. As far as I can see the following two lines should each do this. The first line is neater and is what I initially wrote, but only the second does what I want. The first returns $_SESSION['init'] blank if $initial is blank. Can anyone point out to me where I've been daft? I'm using PHP 5.2.0.

if ($initial!=='') {$_SESSION['init']=$initial;}
if ($initial=='') {} else {$_SESSION['init']=$initial;}

Thanks,
Neil
Link to comment
https://forums.phpfreaks.com/topic/35710-confused-about/
Share on other sites

!== is too strict for what you're after. This operator compares by value [b]and[/b] data type. You're better off using simply !=
[code]
<?php
if ($initial != '') { $_SESSION['init'] = $initial;
?>
[/code]

Hope this helps, and welcome to the forums!

*doh* beat to it again ;)
Link to comment
https://forums.phpfreaks.com/topic/35710-confused-about/#findComment-169186
Share on other sites

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.