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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.