Home >Backend Development >PHP Tutorial >判断一个数组

判断一个数组

WBOY
WBOYOriginal
2016-06-23 13:28:161024browse

比如我在前台输入一个字符串,然后在后台变成数组,跟另外一张表对比.     ['a'=>'1'] ['a=>'2''] ['a'=>'3']如果a=>3和a=>1不存在的话  就提示3和1不存在!
  


回复讨论(解决方案)

$str = 21;$arr = array(1,2,3);if (in_array($str,$arr)){    $index = array_keys($arr,$str);    unset($arr[$index[0]]);    echo implode(',',$arr)."不在数组内";}else{    echo implode(',',$arr)."不在数组内";}

优化下

$str = 21;$arr = array(1,2,3);if (in_array($str,$arr)){    $index = array_keys($arr,$str);    unset($arr[$index[0]]);}    echo implode(',',$arr)."不在数组内";

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
Previous article:PHP下载文件的方式Next article:关于URL重写的问题