November 16, 2016 —John Koster
startsWith
does the opposite of ends_with
, and has the same rules of use. Instead of checking if a given $haystack
ends with any of the supplied $needles
, startsWith
checks if a given $haystack
starts with any of the $needles
.
The signature for the startsWith
helper method is:
startsWith($haystack, $needles)
1use Illuminate\Support\Str; 2 3// true 4Str::startsWith('A simple sentence.', 'A'); 5 6// false 7Str::startsWith('No punctuation here', '.'); 8 9// false10Str::startsWith('Case matters', 'c');11 12// true13Str::startsWith('CASE STILL MATTERS', 'C');
starts_with($haystack, $needles)
The starts_with
function is a shortcut to calling Str::startsWith
. This function is declared in the global namespace.
∎