In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how php7 converts strings into arrays. It is very detailed and has a certain reference value. Friends who are interested must finish it!
Conversion methods: 1, with str_split (), syntax "str_split (str,length)"; 2, with explode (), syntax "explode (separator,str,limit)"; 3, with forced conversion, syntax "(array) string".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Php7 converts strings to arrays
Method 1: use the str_split () function
The str_split () function splits the string into an array according to the specified length, in grammatical format:
Str_split (string,length)
String is required. Specifies the string to be split.
Length is optional. Specifies the length of each array element. The default is 1.
The function FALSE will be returned if length is less than 1. If the length is greater than the length of the string, the entire string is returned as the only element of the array.
Method 2: use the explode () function
The explode () function splits a string into parts with specific delimiters.
The explode () function splits a string based on a string delimiter, that is, it splits a string into several substrings based on the delimiter, and then combines these substrings into an array and returns. The syntax format is as follows:
Explode (separator,string,limit)
The parameters are described as follows:
Separator: delimited characters used to split strings
String: a string that needs to be split
Limit: optional parameter, which can be empty, specifying the number of array elements to be returned
If $limit is not empty and is positive, the returned array contains at most $limit elements, and the last element contains the rest of $string
If $limit is not empty and is negative, all elements except the last $limit element are returned
If $limit is 0, it will be treated as 1
If $limit is empty, all array elements are returned.
Example:
Method 3: cast-cast the variable type (array) by adding the target type in parentheses before the variable
These are all the contents of the article "how php7 converts strings into arrays". Thank you for reading! Hope to share the content to help you, more related knowledge, 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.