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 Quote Link to comment 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)){ Quote Link to comment 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 ;) Quote Link to comment Share on other sites More sharing options...
cumpstey Posted January 26, 2007 Author Share Posted January 26, 2007 Thanks very much!Neil Quote Link to comment 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.