dimanche 25 janvier 2015

Simplify multiple if statements

I'm building a user module in PHP. It reads a text based user type and it assigns a numeric value to manage report view rights:



if ($usr_type == "Architect"){ $usr_rights = 0; }
if ($usr_type == "Director"){ $usr_rights = 1; }
if ($usr_type == "Manager"){ $usr_rights = 2; }
if ($usr_type == "Associate"){ $usr_rights = 3; }
if ($usr_type == "Assistant"){ $usr_rights = 4; }
if ($usr_type == "External"){ $usr_rights = 5; }


Is there a simpler, more elegant way to do this?


Aucun commentaire:

Enregistrer un commentaire