Level 75
$randomWords = ['USA','France','Turkey'];
$term = 'Fran';
$result = collect($randomWords)->contains(function ($value) use ($term) {
return Str::contains($value, $term);
});
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
$randomWords = ['USA','France','Turkey'];
I need to check if substring is contained on my array
Example : 'Fran' is contained (return true)
$randomWords = ['USA','France','Turkey'];
$term = 'Fran';
$result = collect($randomWords)->contains(function ($value) use ($term) {
return Str::contains($value, $term);
});
Please or to participate in this conversation.