Home >php教程 >PHP源码 >多维数组去重和查找

多维数组去重和查找

PHP中文网
PHP中文网Original
2016-05-25 17:14:001346browse

看代码:
$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));

关于去重操作,可用定义一个临时数组,来解决问题!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn