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

判断一个数组

WBOY
Release: 2016-06-23 13:28:16
Original
1008 people have browsed it

比如我在前台输入一个字符串,然后在后台变成数组,跟另外一张表对比.     ['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)."不在数组内";}
Copy after login

优化下

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template