Wednesday, 31 January 2018

php - Filter array by sub element that starts with string

How can I filter an array when a sub element starts with a certain string? This will filter results when 'name' matches 'bk-' but how can I alter it so matched elements starting with 'bk-' instead?



$starts_with = 'bk-';

$new_facets = array_filter($facets, function ($var) use ($starts_with) {
return ($var['name'] == $starts_with);

});

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...