php - Performance topic: If with multiple || or switch case? -


this question has answer here:

i have small script format prices depending on origin of user.
question better performance wise?

function formatprice($price) {         $locale = $this->locale;         switch ($locale) {         case "en-gb":         case "en-ie":         case "he-il":         case "mt-mt":         case "zh-cn":             return number_format($price, 2, '.', ',');         default:             return number_format($price, 2, ',', '.');          }     } 

or

function formatprice($price) {         $locale = $this->locale;         if ($locale === "en-gb" || $locale === "en-ie" || $locale === "he-il" || $locale === "mt-mt" || $locale === "zh-cn") {             return number_format($price, 2, '.', ',');         } else {             return number_format($price, 2, ',', '.');         }     } 

use below link understand more seems compiler better in optimizing switch-statement if-statement. case vs if else if: more efficient?


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -