This article will introduce to you the solution to Strict Standards: Only variables should be passed by reference in. Friends can refer to it.
Use the built-in reset function in php to get the value of the first element of the array. For example:
The code is as follows
代码如下 |
复制代码 |
$arr = array('one', 'two', 'three');
echo reset($arr);
|
|
Copy code
|
代码如下 |
复制代码 |
$str = 'netingcn.com';
echo reset(explode('.', $str));
|
$arr = array('one', 'two', 'three');
echo reset($arr);
| //The output result is one. For the following code, if "Strict Standards" is turned on in PHP, you will see the prompt "Strict Standards: Only variables should be passed by reference in".
Copy code
|
$str = 'netingcn.com';
echo reset(explode('.', $str));
Why is this happening? You can first take a look at the definition of the reset function:
function reset (array &$array) {}As you can see from the definition, the parameter accepted by reset is a reference to an array. The return value of explode in the above code is not a reference to any array, so there will be the above prompt under "Strict Standards". The solution is very simple, just write reset(explode('.', $str)) in two steps. The first step is to assign the return value of explode to a variable, and the second step is to use this variable as the reset parameter.
The above prompt is not just for the reset function. As long as the parameter accepts an object reference and the function return value is used directly to pass the value, you will see such a prompt. For example, built-in array_pop, shuffle, curent, next, prev, next, etc.
http://www.bkjia.com/PHPjc/632075.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632075.htmlTechArticleThis article will introduce to you the solution to Strict Standards: Only variables should be passed by reference in. Friends can refer to it. . Use the built-in reset function in php to get the array...
|