If this sub-string is always in the same place - easy and fast is switch
// $x = string to pass
switch(substr($x,0,2)){
case 'ax': /* do ax */ break;
case 'ab': /* do ab */ break;
case 'ac': /* do ac */ break; // break breaks execution
case 'zy': /* do ZY */ // without a break this and next line will be executed
case 'zz': /* do ZZ */ break; // for zz only ZZ will be executed
default: /* default proceed */}
switch
pass exact values in case
- any other situation are not possible or weird and redundant.
switch
can also evaluate through default
to another one switch
or other conditions
manual