if statement - PHP operators problems -


i building php script. 1 form min_salary , max_salary. trying both of them string in salary variable

$salary = "min_salary max_salary"; 

if min salary not specified should set 0, if max salary not specified should set *.

i have written below code not getting when either of fields not provided.

$salary = (isset($data['min_salary']) ? $data['min_salary'] : 0) .' '. (isset($data['max_salary']) ? $data['max_salary']:'*'); 

also don't want use if else statements.

this line produce code without using if/else statements (even though ternery operator syntactic sugar around if/else statements)

$salary = max(0,$data['min_salary']) . ' ' . ($data['max_salary'] > 0 ? $data['max_salary'] : '*'); 

you don't want same scripting both values 1 should fallback 0 , other *. problem isset():

(isset($data['min_salary']) ? $data['min_salary'] : 0) 

is variable can set empty string $data = '' return true. i'd hazard not want happen.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -