Home > php教程 > php手册 > php 判断多维数组中是否存在指定的 values foreach(),in_array(),

php 判断多维数组中是否存在指定的 values foreach(),in_array(),

WBOY
Release: 2016-06-13 10:46:03
Original
1000 people have browsed it

 

二维数组

 

        function search($keyWord, $stack) {//此处判断是应该更新还是插入

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

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

                    return TRUE;

                }

            }

            return FALSE;

        }

 

 多维数组

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;

}

作者 heicm

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