php中使用内置的reset函数可以获取array的第一个元素的值。例如: $arr = array('one', 'two', 'three');echo reset($arr); // 输出的结果为 one 对于下述代码,如果php开启了“Strict Standards”,将会看到“Strict Standards: Only variables should be p
php中使用内置的reset函数可以获取array的第一个元素的值。例如:
$arr = array('one', 'two', 'three'); echo reset($arr); // 输出的结果为 one
对于下述代码,如果php开启了“Strict Standards”,将会看到“Strict Standards: Only variables should be passed by reference in”的提示。
$str = 'netingcn.com'; echo reset(explode('.', $str));
为什么会这样呢?可以先看看reset函数的定义:
function reset (array &$array) {}
从定义中可以看到,reset接受的参数是一个array的引用。而上述代码中explode返回值不是任何array的引用,所以在“Strict Standards”下会有上述提示。解决办法很简单,只需要把reset(explode(‘.’, $str))分两步写即可。第一步先把explode的返回值赋给一个变量,第二步把这个变量作为reset参数。
出现上面的提示的不只是reset函数,只要参数接受的是对象引用,而传值直接使用function返回值都会看到那样的提示。例如内置的array_pop、shuffle、curent、next、prev、next等等。
原文地址:Strict Standards: Only variables should be passed , 感谢原作者分享。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号