• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clarity on Session Code

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

Thanks in advance

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.

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


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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.