我正在尝试将 in_array 或类似的东西用于关联数组或更复杂的数组。
这是普通的 in_array
in_array('test', array('test', 'exists')); //true
in_array('test', array('not', 'exists')); // false
我要搜索的是对,例如“test”和“value”的组合。我可以根据需要将要搜索的组合设置为 array('test','value')
或 'test'=>'value'
。但是,如果要搜索的数组是
array('test'=>'value', 'exists'=>'here');
or
array( array('test','value'), array('exists'=>'here') );
最佳答案
if (
array_key_exists('test', $array) && $array['test'] == 'value' // Has test => value
||
in_array(array('test', 'value'), $array) // Has [test, value]
) {
// Found
}
关于php - in_array 组合值 ('test' ,'value' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5280754/