PHP values are easy to use. Loop traversal and class pointer (personally called) can be used. However, if the last value of the array is also traversed, does it consume a lot of performance? Method 1:
Output
// Output 8
Method 2:
Output
// Output 8
Method 3:
Output
Array ( [0] => 8 )
The second method has a drawback. the Array_pop () function will "fetch" the last number of the original data, which is equivalent to cutting, the original data will no longer have the last value.
For example:
Output:
Array ( [0] => 1 [1] => 2 [2] => 4 [3] => 6 )
The above are all built-in functions in PHP. In fact, we can also get the last element in the PHP array through some of our own methods.
Of course, if the built-in method can be implemented, we should try to use the built-in function of PHP, because the built-in method is the most efficient in terms of efficiency and time, but in the development process, if we do not know whether this method exists or do not remember this method, we can also write the function method we want based on our own logic.