In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "php how to add elements from the end of the array", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "php how to add elements from the tail of the array" bar!
Method: 1, use "array_push (array, element list)", can insert one or more elements in the tail; 2, use "array_splice (array, count (array), 0, insert value)"; 3, use "array_merge (array 1, array 2)", put the value of array 2 into array 1.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Php's method of adding elements from the end of an array
1. Use the array_push () function to add elements from the end of the array
The array_push () function can insert one or more elements (key values) at the end of the array, with the following syntax:
Array_push ($array,$value1,$value2...)
Example:
You can see that three elements are inserted at the end of the $arr array: the integer "8", the string "9", and the floating point number "3.14".
The element inserted by the array_push () function can be an array type
2. Use the array_splice () function to add elements from the end of the array
The array_splice ($array,$start,$length,$value) function is a powerful function that can be used to delete array elements, replace array elements, 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).
And when the value of $start is set to "array length value", that is, count ($arr), you can insert elements at the end of the array.
The output is as follows:
3. Use the array_pad () function to add elements from the end of the array
The array_pad ($array,$size,$value) function inserts a key value of $value into the array $array, thus filling the array to a specified length of $size. The $size parameter can be understood as the final number of elements in the array, that is, the length of the array after the insert operation.
So how do you use the array_pad () function to add elements from the end of the array? The key is the $size parameter.
When the $size parameter is positive, the element is inserted at the end of the array.
The element inserted by the array_pad () function can be an array type, so the original array becomes a two-dimensional array.
The output is as follows:
4. Use the array_merge () function to add elements from the end of the array
Array_merge (array1,array2,array3...) Function is used to merge one or more arrays into one array, setting the array2,array3... Is stored in array1
If two or more array elements have the same key name, the last element overrides the other elements.
Thank you for reading, the above is the content of "php how to add elements from the end of the array". After the study of this article, I believe you have a deeper understanding of how php adds elements from the end 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.