How php deletes elements with even keys in an array
The knowledge of this article "php how to delete the even number of elements in the array" is not understood by most people, so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "php how to delete the even number of elements in the array" article.
Delete method: 1, use the "foreach ($arr as $key= > $value" statement to loop through the array; 2, in the loop body, use the "$key%2==0" statement to determine whether the key is even; 3, if it is an even number, use the "unset ($arr [$key])" statement to delete the element.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Php deletes elements with even keys in the array
Implementation method:
Loop through the array using the foreach statement
Foreach ($array as $key = > $value) {statement block;}
Iterate through the given $array array, assigning the value of the current array to $value and the key name to $key in each loop.
In the body of the loop, use the $key%2==0 statement to determine whether the key is even.
If even, delete using the unset () function
Implementation code:
The above is about the content of this article on "how php deletes the elements whose keys are even in the array". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.