"search for partial value match in an array" Code Answer

2

Use array_filter. You can provide a callback which decides which elements remain in the array and which should be removed. (A return value of false from the callback indicates that the given element should be removed.) Something like this:

$search_text = 'Bread';

array_filter($array, function($el) use ($search_text) {
        return ( strpos($el['text'], $search_text) !== false );
    });

For more information:

  • array_filter
  • strpos return values
By tesarova.terka-fdaafdb573ba on September 14 2022

Answers related to “search for partial value match in an array”

Only authorized users can answer the search term. Please sign in first, or register a free account.