How php adds elements to the end of a two-dimensional array
This article mainly introduces how php adds elements at the end of the two-dimensional array, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this php article on how to add elements at the end of the two-dimensional array. Let's take a look.
The method of adding elements: 1, use the array_push () function, syntax "array_push (two-dimensional array, value 1, value 2...)"; 2, use the array_splice () function, syntax "array_splice (two-dimensional array, count (two-dimensional array), 0, element value)".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
The method of adding elements at the end of two-dimensional array by php
1. Use the array_push () function
The array_push () function inserts one or more elements (key values) at the end of the array.
The added element can also be an array type:
Array_push ($arr,array ("Li Hua", 22, "male")
2. Use the array_splice () function
The array_splice () function is a powerful function that can be used to delete, replace, or insert array elements (just set the parameter $length to 0).
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).
To insert an element at the end of an array, simply set the value of $start to "array length value", that is, count ($arr).
If you want to add more than one element, set the four parameters to the array type
Array_splice ($arr,count ($arr), 0Jane array ("1", 25, "3"))
This is the end of the article on "how php adds elements to the end of a two-dimensional array". Thank you for reading! I believe you all have a certain understanding of "how to add elements at the end of a two-dimensional array". If you want to learn more, you are welcome to follow the industry information channel.