Comparing string with "enumeration" of strings in php -


i wanna compare string "enumeration", can simplier in solution bellow? first know enum type not implemented in php.
problem question is: string s equal 1 of strings? since php don't have enum, values of enum in array or that.

 //$min_s string value of minute value example "15". if((strcmp($min_s, "00")== 0 || str_cmp($min_s,"15") == 0 ||             strcmp($min_s, "30")== 0 || strcmp($min_s, "45") == 0) { // ok}

goal:
make ifs more readable specific example , others in future when wanna compare string "enum".

to answer question literally:

$fifteens = array('00', '15', '30', '45'); if (in_array($min_s, $fifteens)) {     ... } 

but use arithmetic:

if ($min_s % 15 == 0) {     ... } 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -