我只想在此循环中获得数组的确切结果:
<?php
$color_groups = [
"green" => array('lightgreen', 'green', 'olive', 'malachite'),
"blue" => array('blue', 'skyblue', 'cyan', 'iris', 'navyblue', 'zaffre')
];
$selected_color_str = 'cyan';
foreach ($color_groups as $key => $value) {
foreach ($value as $color) {
if (preg_match('/' . $color . '/i', $selected_color_str)) {
echo $key;
} else {
echo " not_found ";
}
}
}
?>
Result:个
未找到blue未找到未找到
- 但我只想显示blue,如果该数组中存在,如果不是ECHO NOT_FOUND的话