Multiple Statements For The Ternary Operator Of PHP -


i'm wondering if use ternary operator this:

var string = ""; if (something) {   string = "foo" } else if (somethingelse) {   string = "bar"; } else if (bla) {   string = "pool"; } else if (xxxxx) {   string = "coffee"; } else {   string = ""; } 

as far remember, can in java language:

string string = something?"foo":somethingelse?"bar":bla?"pool":xxxxx?"coffee":""; 

but i'm not sure php, i'm not sure if it's ok use ternary operator in case or not.

e.g

 if (something) {       string = "foo"     } else if (somethingelse) {       string = "bar";     } else if (bla) {       string = "pool";     } else if (xxxxx) {       string = "coffee";     } else {       string = ""; } 

is equivalent in php

(something) ? 'foo' : ((somethingelse) ? 'bar' : ((bla) ? 'pool' : ((xxxxx) ? 'coffe' : ''))); 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -