Is this if equivalent to this ternary ($ no % 3 = 1 )? $ Num = 1 :( $ no % 3 = 2 ))? $ Num = 2 :( $ no % 3 = 0 ))? $ Num = 3: false;
And
If ($ no1 % 3 = 1 ){
$ Num1 = 1;
} Elseif ($ no1 % 3 = 2 ){
$ Num1 = 2;
} Elseif ($ no1 % 3 = 0 ){
$ Num1 = 3;
}
I tried it. if is displayed, but if is not displayed, I don't know where it is wrong.
Reply to discussion (solution)
$ Num = 3: false; in this case, the value is first assigned, and the value is directly false ..
Looking at the trend, the poster is sheep_app3.
$ Map = array (3, 1, 2); $ num1 = $ map [$ no % 3];
($ No % 3 = 1 )? $ Num = 1 :( ($ no % 3 = 2 )? $ Num = 2 :( ($ no % 3 = 0 )? $ Num = 3: false ));
Your ternary and if are not equivalent. take a closer look at your ternary and only get two results, $ num = 3 or false.
The above answer is not for the landlord, but for those who only use if and switch, another idea is to use hashtable, which has the highest efficiency when many branches exist.