Monday 15 June 2015

if statement - PHP code for more than 3 states -


If you have three states, then you can use elseif and the other show your dynamic page with three options. for. Below the file

  if ($ user == 1) {// code has been inserted here for the first code} elseif ($ user == 2) {// put code second For the state} Other {// places the code here for the original position}   

But I have 5 states in this way. $ user == 2 , $ user == 3 , how can I use to dynamite my page $ user == 1 , $ user == 2 , $ user == 4 and default (I $ user == *

Have you heard about it? :) Switch ($ user) {Case 1: // Break something; Case 2: // Break something; Case 3: // Break something; Case 4: // Something Smash; Case 5: // Break something; Default: // Something break; }

Note that the numbers after the case in this case are not syntax, or the conference or whatever may be. In fact, those values ​​that you compare with $ user can also be the case 'this is a string': , which is the value of $ user string of 'string' .

No comments:

Post a Comment