CodeIgniter Forums
Clarity on Session Code - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Clarity on Session Code (/showthread.php?tid=67288)



Clarity on Session Code - ojchris - 02-05-2017

What does this line of code imply: ($this->session->userdata('is_user_login')==TRUE)?'4':'4'

Thanks in advance


RE: Clarity on Session Code - twpmarketing - 02-05-2017

The ternary operator in this statement will evaluate to a text value '4', whether the session userdata element has a value of TRUE or not. Doesn't appear to be very useful when taken outside of the context in which this term is used.

If you could provide more of the code in which this statement is used, it might help us give a better answer.


RE: Clarity on Session Code - Diederik - 02-06-2017

I hope this example with other values will make it more clear. Setting both cases to the same value (4) does not make any sense.

PHP Code:
$myValue = ($this->session->userdata('is_user_login') == TRUE) ? '4' '6'); 

This is shorthand for this if / else statement

PHP Code:
if ($this->session->userdata('is_user_login') == TRUE) {
 
   $myValue '4';
} else {
 
   $myValue '6';




RE: Clarity on Session Code - ojchris - 04-19-2017

thank you twpmarketing and Diederik for your help on this. Very clear