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

回到static的变量变成了null

WBOY
Release: 2016-06-13 12:13:27
Original
1200 people have browsed it

返回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 />
Copy after login

为什么打印出来的结果是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));
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