Ad

Laravel In_array() Function Part Of String Detect

- 1 answer

Here is array as following:

$array = ['blog.setting', 'blog.post', 'blog.delete', 'blog.edit', 'other.other'];

I want to know if there is element which has 'blog.'; Maybe like this will be perfect.

in_array('blog.*', $array)

Can anyone help me?

Ad

Answer

As you mentioned Laravel in your tags, you could do:

use Illuminate\Support\Str;
use Illuminate\Support\Collection;

$blogTest = Collection::make($array)
    ->contains(function ($elt) {
        return Str::is('blog.*', $elt);
    });
Ad
source: stackoverflow.com
Ad