This article introduces the Strict Standards: Only variables shocould be passed by reference in solution. For more information, see.
Php uses the built-in reset function to obtain the value of the first element of array. For example:
The Code is as follows: |
Copy code |
$ Arr = array ('one', 'two', 'three '); Echo reset ($ arr ); |
// The output result is one. If "Strict Standards" is enabled for php, the prompt "Strict Standards: Only variables shocould be passed by reference in" is displayed.
The Code is as follows: |
Copy code |
$ Str = 'netingcn. com '; Echo reset (explode ('.', $ str )); |
Why? Let's first look at the definition of the reset function:
Function reset (array & $ array) {} can be seen from the definition that the reset accepts the parameter as an array reference. In the above Code, the return value of explode is not referenced by any array, so the above prompt is displayed under "Strict Standards. The solution is simple. You only need to write the 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 a reset function, as long as the parameter accepts the object reference, and the function return value is directly used to pass the value. For example, the built-in array_pop, shuffle, curent, next, prev, And next