Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How php converts a string to array

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

In this issue, the editor will bring you about how php converts strings into array. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Conversion method: 1, using the explode () function, you can split a string into several substrings according to the delimiter, and then combine these substrings into an array and return, syntax "explode (delimiter, string)"; 2, use the str_split () function, syntax "str_split (string)".

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Method 1 for php to convert a string to array (array): use the explode () function

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 ($delimiter, $string [, $limit])

The parameters are described as follows:

$delimiter: the delimited character used to split the string

$string: the string to be split

$limit: optional parameter, which can be empty to specify 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:

Output result:

Method 2 of php converting a string to array (array): use the str_split () function

The str_split () function splits the string into an array.

Grammar

Str_split (string,length)

The parameters are described as follows:

String is required. Specifies the string to be split.

Length is optional. Specifies the length of each array element. The default is 1.

Example:

Output result:

This is how the php shared by the editor converts the string into array. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report