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

递归引用有关问题

WBOY
Release: 2016-06-13 12:00:50
Original
868 people have browsed it

递归引用问题

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

------解决方案--------------------
规则问题
Fatal error: Call-time pass-by-reference has been removed
致命错误:传递引用的做法已被废止
要这么写
function array_format(&$data){<br />    foreach($data as $k => &$v){<br />        if(is_array($v)) {<br />            array_format($v);<br />        }else{<br />            if(is_null($v)) $v = "";<br />            $v = htmlspecialchars_decode($v);<br />        }<br />    }<br />    return $data;<br />}
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