preg_grep

preg_grep is very useful too as it can search for a pattern within an array, and return the array elements that match said pattern.

Its mostly used to filter certain patterns out of an array list.

Usage

preg_grep('/"node_modules\/.+|"version": ".+/', $separatedPatch)

Here I filter a patch file that has its lines separated into array elements by preg_split and return the files that either contain “node modules” or “version” so basically the only relevant ones for this app.