In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "php how to add data to the array", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "php how to add data to the array" can help you solve your doubts.
Php's method of adding data to an array: 1. Use "array_unshift (array, value 1, value 2.)" Statement; 2. Use "array_push (array, value 1, value 2.)" Statement; 3. Use the "array_splice (array, start position, 0, value)" statement.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Php adds data to the array
Method 1:array_unshift () function
Array_unshift ($array,$value1,$value2...) Function can insert one or more new elements (key values) at the beginning of the array.
Method 2:array_push () function
Array_push ($array,$value1,$value2...) Function can insert one or more elements (key values) at the end of the array.
Method 3:array_splice () function
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).
Method 4:array_pad () function
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.
As you can see from array_pad ($arr,5,1), if the value of $size is 5, there are five elements in the array after the insert operation, while there are already three elements, so you only need to insert two elements. And because the insert value $value is 1, you only need to insert two elements with a value of "1". So the output is:
After reading this, the article "php how to add data to arrays" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.
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.