Home > Backend Development > PHP Tutorial > PHP中封存key值把value置0,嵌套数组可用

PHP中封存key值把value置0,嵌套数组可用

WBOY
Release: 2016-06-13 12:19:36
Original
992 people have browsed it

PHP中保留key值把value置0,嵌套数组可用

实现一个把PHP数组中所有元素设置为0的函数,用了递归

public  function setArraytoZero(&$array) {        foreach ($array as &$value){            if(is_array($value)) {                $this->setArraytoZero($value);            }            else {                $value = 0;            }        }    }
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