In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how php intercepts the last few bits of an array. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Php intercepts the last few elements of the array: 1, use the "array_slice ($array,$start)" statement, the parameter "$start" should be negative; 2, use the "array_splice ($array,$start)" statement, the parameter "$start" should be negative.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Php intercepts the last few elements of the array
1. Use the array_slice () function
The array_slice () function is a function provided by PHP to intercept an array and extract a fragment from the array. The syntax is as follows:
Array array_slice (array $arr, int $start [, int $length = NULL [, bool $preserve_keys = false]])
Parameter description:
Arr represents the array to be intercepted.
Start indicates where to start the intercept (subscript):
If start is positive, it is intercepted from the back of the go.
If the start is negative, it is intercepted from back to front, starting at the distance from the end of the arr-start. For example,-2 means starting with the penultimate element of the array.
Length is an optional parameter that indicates the intercept length:
If length is positive, it indicates the number of elements intercepted
If length is negative, the intercepted fragment will terminate at the position of length at the end of the distance array
If omitted, it starts at the start position and goes all the way to the end of the array.
Preserve_keys is an optional parameter, which specifies whether to keep the original key name. The default is false, that is, it is not retained. If set to true, the original key name will be retained.
Example: intercept the last few elements of an array
To intercept the last few elements of the array, simply set the parameter start to a negative value
Output result
2. Use the array_splice () function
When the array_splice () function deletes some elements of an array, it combines the deleted elements into a new array and then returns the new array; so the array_splice () function can be used to intercept the array fragments.
As with the array_slice () function, you can intercept the last few elements of the array simply by setting the second parameter, start, to a negative value.
Output result
Thank you for reading! This is the end of this article on "how php intercepts the last few bits of the array". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.