Home >Backend Development >PHP Tutorial >递归引用问题

递归引用问题

WBOY
WBOYOriginal
2016-06-23 13:54:421006browse

function array_format($data){    foreach($data as $k => &$v){        if(is_array($v)) {        	array_format(&$v); //这个是关键。在5.3版本可以使用.在5.4版本不能用。这个是什么问题?        }else{	        if(is_null($v)) $v = "";	        $v = htmlspecialchars_decode($v);        }    }    return $data;}


回复讨论(解决方案)

规则问题
Fatal error: Call-time pass-by-reference has been removed 
致命错误:传递引用的做法已被废止
要这么写

function array_format(&$data){    foreach($data as $k => &$v){        if(is_array($v)) {            array_format($v);        }else{            if(is_null($v)) $v = "";            $v = htmlspecialchars_decode($v);        }    }    return $data;}

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