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

WBOY
Release: 2016-07-13 17:47:32
Original
864 people have browsed it

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...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!