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: