Home > Backend Development > PHP Problem > How to use php str_split() function

How to use php str_split() function

青灯夜游
Release: 2023-03-11 06:04:01
Original
3330 people have browsed it

In PHP, the str_split() function is used to split a string into an array, that is, convert a given string into an array, the syntax is "str_split(string, element length)". This function splits a given string into smaller strings of user-specified length, stores them in an array and returns the array.

How to use php str_split() function

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

str_split() is a built-in function in PHP. Used to split a string into an array and convert the given string into an array. This function basically splits the given string into smaller strings of user-specified length and stores them in an array and returns the array.

Syntax

str_split(string,length)
Copy after login
ParametersDescription
string Required. Specifies the string to be split.
length Optional. Specifies the length of each array element. The default is 1.

Return value: If length is less than 1, the str_split() function will return FALSE. If length is greater than the length of the string, the entire string is returned as the only element of the array.

Example 1:

<?php
$string = "Hello";
print_r(str_split($string));
?>
Copy after login

Output:

Array ( [0] => H [1] => e [2] => l [3] => l [4] => o )
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to use php str_split() function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template