多维数组去重和查找
程序员文章站
2022-05-02 12:45:08
...
看代码:
$a = array(array('p', 'h'), array('p', 'r'), 'o');
if (in_array(array('p', 'h'), $a)) {
echo "'ph' was found\n";
}
if (in_array(array('f', 'i'), $a)) {
echo "'fi' was found\n";
}
if (in_array('o', $a)) {
echo "'o' was found\n";
}
支持多维数组查找!
$key=array('0'=>array('en_term' =>'h','pos'=>'n','cn_define'=>'你'),'1'=>array('en_term' =>'w','pos'=>'n','cn_define'=>'好'));
//bool(true)
var_dump(in_array(array('en_term' =>'h','pos'=>'n','cn_define'=>'你'),$key));
关于去重操作,可用定义一个临时数组,来解决问题!
$a = array(array('p', 'h'), array('p', 'r'), 'o');
if (in_array(array('p', 'h'), $a)) {
echo "'ph' was found\n";
}
if (in_array(array('f', 'i'), $a)) {
echo "'fi' was found\n";
}
if (in_array('o', $a)) {
echo "'o' was found\n";
}
支持多维数组查找!
$key=array('0'=>array('en_term' =>'h','pos'=>'n','cn_define'=>'你'),'1'=>array('en_term' =>'w','pos'=>'n','cn_define'=>'好'));
//bool(true)
var_dump(in_array(array('en_term' =>'h','pos'=>'n','cn_define'=>'你'),$key));
关于去重操作,可用定义一个临时数组,来解决问题!