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

How to use php str_split() function

青灯夜游
青灯夜游Original
2021-06-29 18:41:343285browse

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)
Parameters Description
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));
?>

Output:

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

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!

Statement:
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