Home  >  Article  >  Backend Development  >  PHP determines whether specified values ​​exist in a multidimensional array foreach(), in_array(),_PHP tutorial

PHP determines whether specified values ​​exist in a multidimensional array foreach(), in_array(),_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:47:32904browse

Two-dimensional array

          function search($keyWord, $stack) {//Determine whether to update or insert here

foreach ($stack as $key => $val) {

If (in_array($keyWord, $val)) {

                        return TRUE;

                  }

            }

              return FALSE;

}

Multidimensional array

www.2cto.com

function search($array, $v) {

$data = array();

foreach ($array as $key => $value) {

If (is_array($value)) {

               $result = test($value, $v);

If (!empty($result)) {

                    $data[$key] = $result;

            }

         } else {

                  if ($value == $v) {

                    $data[$key] = $v;

            }

}

}

Return $data;

}

Author heicm

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478496.htmlTechArticleTwo-dimensional array function search($keyWord, $stack) {//Judge here whether to update or insert foreach ($stack as $key = $val) { if (in_array($keyWord, $val)) { return TRUE; } } return...
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