Home >Backend Development >PHP Tutorial >回到static的变量变成了null

回到static的变量变成了null

WBOY
WBOYOriginal
2016-06-13 12:13:271173browse

返回static的变量变成了null

本帖最后由 Sbaoge 于 2015-01-02 02:11:39 编辑
<br />	function d($data) {<br />		static $r = array();<br />		$r[] = array_shift($data);<br />		if(!count($data)) {<br />			return $r;<br />		}else {<br />			d($data);<br />		}<br />	}<br />	$arr = array(1,2,3);<br />	var_dump(d($arr));<br />

为什么打印出来的结果是null?
------解决思路----------------------
function d($data) {
    static $r = array();
    $r[] = array_shift($data);
    if(!count($data)) {
        return $r;
    }else {
        return d($data);
    }
}
$arr = array(1,2,3);
var_dump(d($arr));
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