How php adds elements to an array
This article mainly introduces php how to add elements in the array of related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this php how to add elements in the array of articles will have a harvest, let's take a look.
In php, you can use the array_splice () function to add elements in the middle of an array by setting the second parameter of the function to a value greater than 0 and less than "array length-1", syntax "array_splice (array, index position to be inserted, 0, element value)".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Php adds elements in the middle of the array
In php, you can use the array_splice () function to add elements in the middle of an array.
The array_splice ($array,$start,$length,$value) function inserts a new element anywhere in the array.
When $length=0, the parameter $start specifies where to start the insertion (subscript), and the parameter $value specifies the insertion value (if it is multiple values, it needs to be set to an array).
Example:
You can see that when the value of the parameter $start is greater than 0 and less than Array length-1, you can add elements in the middle of the array.
This is the end of the article on "how php adds elements to arrays". Thank you for reading! I believe you all have a certain understanding of "how to add elements to the array by php". If you want to learn more, you are welcome to follow the industry information channel.