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

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

WBOY
WBOYOriginal
2016-06-13 12:19:36915browse

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

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

public  function setArraytoZero(&$array) {        foreach ($array as &$value){            if(is_array($value)) {                $this->setArraytoZero($value);            }            else {                $value = 0;            }        }    }


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