In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how php removes the first element of an array". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "php how to eliminate the first element of an array".
Elimination methods: 1, with array_shift () function, syntax "array_shift ($arr)"; 2, with array_splice () function, syntax "array_splice ($arr,0,1)"; 3, with "array_slice ($arr,1)" statement.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Php weeds out the first element of the array
Method 1: use the array_shift () function
The PHP array_shift () function deletes the elements at the beginning of the array
As you can see in this example, our original $arr array has five elements. After using the array_shift ($arr) method, we re-use var_dump ($arr) to output the array, and we find that there are only four elements left, and the array header element has been deleted.
After the array_shift ($arr) function deletes the first element at the beginning of the $arr array, the length of the arr array is reduced by 1 and all other elements are moved forward one bit. If the key name is numeric, all elements will get the new key name, starting at 0 and incrementing by 1, but the string key name will remain the same.
And after we perform the delete operation, we output the original array to see whether the element is deleted. It is not difficult to find that array_shift () will change the original array.
Method 2: use the array_splice () function
The array_splice () function is used to delete some elements of the array; you can delete it directly or replace it with other values.
Example: delete the first element in the array
Method 3: use the array_slice () function
The array_slice () function is used to intercept an array, that is, to extract a fragment from the array.
Return value: returns the intercepted subarray.
Thank you for reading, the above is the content of "how php removes the first element of the array". After the study of this article, I believe you have a deeper understanding of how php removes the first element of the array, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.