代码链接:http://www.mcqyy.com/RunCode/php/#id/29b4699b9f37cc352dcf1e39c7491e86
代码:
<?php
$arr = array();
main();
array_push($arr,'2');
arrSearch($arr,'2');
arrSearch($arr,'1');
function main(){
global $arr;
array_push($arr,'1');
arrSearch($arr,'1');
}
function arrSearch($arr,$el){
echo "<hr>";
echo "arr:";
print_r($arr);
echo "<br/>";
echo $el.":";
if(array_search($el,$arr)){
echo 'yes';
}else{
echo 'no';
}
}
?>
结果是:
arr:Array ( [0] => 1 )
1:no
arr:Array ( [0] => 1 [1] => 2 )
2:yes
arr:Array ( [0] => 1 [1] => 2 )
1:no
ps:刚学php,还请大家指教。