if (substr('xcazasd123', 0, 2) === 'ax'){ }
Above code is working where it able to check if the “variable” is starting with ‘ax’, but what if i wanted to check “multiple” different validation ?
for example : ‘ax’,’ab’,’ac’ ? Without creating multiple if statement
Advertisement
Answer
You can use array to store your keywords and then use in_array()
if you want to avoid multiple if statements.
$key_words =["ax","ab","ac"] if (in_array( substr('yourstringvalue', 0, 2), $key_words ){ //your code }
References: in_array — Checks if a value exists in an array