php - In performance aspect which one is best if or switch or ternary? -


i new php.

in php there 3 conditional structures

  1. if 2.switch 3. ternary

among these 3 1 best improve program performance ?

please tell me in conditions need preference if or switch or ternary , why ?

how increases performance based on condition , execution time ?

there no performance issue of using any. depends on situation, use. use ternary operator if condition not complex

like :-

$num = $num == 1?'yes':'no' 

its better use ternary operator reduce code size more complex conditions, can become confusing so, use if

switch should use when condition same of case.

if($num == 1 || $num == 2 || $num == 3 || $num == 5 || $num == 7 || $num == 11 ) {     // } 

at situation if should replace switch, make code cleaner


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -