Welcome Guest, Not a member yet? Register   Sign In
Clarity on Session Code
#1

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

Thanks in advance
Reply
#2

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.
CI 3.1 Kubuntu 19.04 Apache 5.x  Mysql 5.x PHP 5.x PHP 7.x
Remember: Obfuscation is a bad thing.
Clarity is desirable over Brevity every time.
Reply
#3

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';

Reply
#4

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




Theme © iAndrew 2016 - Forum software by © MyBB