Skip to content

Instantly share code, notes, and snippets.

@reactormade
Last active December 14, 2015 07:48
Show Gist options
  • Save reactormade/5052806 to your computer and use it in GitHub Desktop.
Save reactormade/5052806 to your computer and use it in GitHub Desktop.
Extract a string from an array of string if it matches to a another string (comparison)
function extract_matching_string_from_array($array_of_strings, $comparison){
$array = array();
foreach ($array_of_strings as $string):
if (strstr($string, $comparison)):
array_push($array, $string);
endif;
endforeach;
return $array;
}
//$another = extract_matching_string_from_array($string, 'something-to-compare');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment