CodeIgniter Forums
switch on input->post() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: switch on input->post() (/showthread.php?tid=29483)



switch on input->post() - El Forum - 04-11-2010

[eluser]Ngulo[/eluser]
hi guys ,i'm getting problems making a simple switch on $this->input->post('asd',TRUE);

i would like to switch in case it is null or is not Null ,any suggestion code?

i really don't know how to make this switch

guessing i would like something like this:

Code:
switch($this->input->post('asd'))
{
case is null:
i do this
break;

case is not null:
i do this other
break;
}

does anyone knows how to build perfectly this switch ?

thanks a lot Wink


switch on input->post() - El Forum - 04-11-2010

[eluser]erik.brannstrom[/eluser]
I don't see why you don't just use a regular if-else statement since you only have two alternatives.

Anyway, the following should work, though you should be aware that switch uses loose comparison (== and not ===), so a value of 0 or FALSE would also be considered to be NULL.

Code:
switch($this->input->post('asd')) {
  case NULL:
    //i do this
    break;
  default:
    //i do this other
}



switch on input->post() - El Forum - 04-11-2010

[eluser]Ngulo[/eluser]
sorry man you are right Wink

the story is that i have more than 2 cases and i was looking to didn't post all my code wich is so longer than the one i posted Wink

thanks for suggestion Wink