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 Answer You can use array to store your keywords and then use in_array() if you want to avoid multiple if statements. References: in_array
Tag: string-matching
How do I check if a string contains a specific word?
This question’s answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions. Consider: Suppose I have the code above, what is the correct way to write the statement if ($a contains ‘are’)? Answer Now with PHP 8 you can do this using str_contains: RFC Before PHP 8 You can