Home > php教程 > php手册 > PHP two-dimensional array to verify whether a value exists

PHP two-dimensional array to verify whether a value exists

WBOY
Release: 2016-10-17 09:12:06
Original
2289 people have browsed it

PHP determines whether the number is in a two-dimensional array
$arr = array( <br> array('a', 'b'), <br> array('c', 'd') <br> ); <br> ​ <br> in_array('a', $arr); // What is returned at this time is always false <br> deep_in_array('a', $arr); // Returns true value at this time <br> ​ <br> function deep_in_array($value, $array) { <br> foreach($array as $item) { <br> If(!is_array($item)) { <br>                 if ($item == $value)                                                                                                                                                                                                                                                          return true; } Else {s                                                                                continue;                                                                                                                                                                                                  If(in_array($value, $item)) { <br> Return true;             } else if(deep_in_array($value, $item)) {                                                                               Return true;           } <br>  } <br> Return false; <br> }<br> <br><br><br><br> <br>

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template