There is a PHP function: preg_grep
which accepts $pattern
and $input
as a parameters and returns you an array of matches. If you want to get first match just assign it to variable, e.x.:
$field_os = array('windows-7','mac-os-10.07','linux-ubunto-16.04');
$user_os_type = "windows";
$matches = preg_grep("https://wordpress.stackexchange.com/" . $user_os_type . "https://wordpress.stackexchange.com/", $field_os);
var_dump($matches);
/*
Prints:
array(1) {
[0]=>
string(9) "windows-7"
}
*/
$first_match = $matches[0];
echo $first_match; // Prints: windows-7
For more information visit this link: http://php.net/manual/en/function.preg-grep.php