Reputation: 3764
What is the simplest way of checking whether the first letter of a string $str
is 'a'
and the last letter is 'a'
too?
Upvotes: 13
Views: 12294
Reputation: 11556
Or use substr to get the last character:
if($str[0] == 'a' && substr($str,-1) == 'a') {
//do whatever you wanted
}
Upvotes: 2
Reputation: 2611
if($str[0] == 'a' && $str[strlen($str) - 1] == 'a') {
//do whatever you wanted
}
Upvotes: 24