Search for partial value match in an Array

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

From PHP8, there is a new function to return a boolean value to express whether a substring occurs in a string (this is offered as a simpler replacement for strpos()).

str_contains()

This would need to be called within an iterating function/construct.

From PHP7.4 arrow functions can be used reduce the overall syntax and invite global variables into the custom function's scope.

Code: (Demo)

$array = [
    ['text' => 'I like Apples', 'id' => '102923'],
    ['text' => 'I like Apples and Bread', 'id' =>'283923'],
    ['text' => 'I like Apples, Bread, and Cheese', 'id' => '3384823'],
    ['text' => 'I like Green Eggs and Ham', 'id' =>'4473873']
];

$search = 'Bread';
var_export(
    array_filter($array, fn($subarray) => str_contains($subarray['text'], $search))
);

Output:

array (
  1 => 
  array (
    'text' => 'I like Apples and Bread',
    'id' => '283923',
  ),
  2 => 
  array (
    'text' => 'I like Apples, Bread, and Cheese',
    'id' => '3384823',
  ),
)