cumpstey Posted January 25, 2007 Share Posted January 25, 2007 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 More sharing options...
Jessica Posted January 25, 2007 Share Posted January 25, 2007 !== compares types as well as value, not what you want here. Try != or instead useif(!isset($initial)){ Link to comment https://forums.phpfreaks.com/topic/35710-confused-about/#findComment-169183 Share on other sites More sharing options...
obsidian Posted January 25, 2007 Share Posted January 25, 2007 !== 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]<?phpif ($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 More sharing options...
cumpstey Posted January 26, 2007 Author Share Posted January 26, 2007 Thanks very much!Neil Link to comment https://forums.phpfreaks.com/topic/35710-confused-about/#findComment-169461 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.