PHP determines whether the two-dimensional array contains a certain value:
PHP can use loop traversal to compare each value in the two-dimensional array with the query Values are compared to determine whether a certain value is contained in the two-dimensional array.
$arr = array( array('a', 'b'), array('c', 'd') ); in_array('a', $arr); // 此时返回的永远都是 false deep_in_array('a', $arr); // 此时返回 true 值 function deep_in_array($value, $array) { foreach($array as $item) { if(!is_array($item)) { if ($item == $value) { return true; } else { continue; } } if(in_array($value, $item)) { return true; } else if(deep_in_array($value, $item)) { return true; } } return false; }
Recommended: php server
The above is the detailed content of Does php two-dimensional array have a certain value?. For more information, please follow other related articles on the PHP Chinese website!