1.php 中的数组底层实现是hashtable,参见http://www.laruence.com/2009/08/23/1065.html
因而要区别key/索引,跟value的区别
2.判断KEY是否存在:array_key_exists(key,array),http://www.w3school.com.cn/php/func_array_key_exists.asp
<?php $a=array("a"=>"Dog","b"=>"Cat"); if (array_key_exists("a",$a)) { echo "Key exists!"; } else { echo "Key does not exist!"; } ?>输出为:
Key exists!
3.判断value是否存在:in_array(value,array,type),http://www.w3school.com.cn/php/func_array_in_array.asp
<?php $people = array("Peter", "Joe", "Glenn", "Cleveland"); if (in_array("Glenn",$people)) { echo "Match found"; } else { echo "Match not found"; } ?>输出为:
Match found