Home  >  Article  >  Backend Development  >  PHP operates string split into array

PHP operates string split into array

php中世界最好的语言
php中世界最好的语言Original
2018-05-18 11:21:477664browse

This time I will bring you php operationStringsplit intoarray, what are the precautions for php operation string split into array, the following are Let’s take a look at practical cases.

The example is as follows:

<?php
$str="1|2|3|4|5|";
$var=explode("|",$str);
print_r($var);
?>
$var=explode("|",$str);

Split $str by |

php and other ways to specify strings Characters are split into arrays

str_split(string,length)

Parameter description

string Required. Specifies the string to be split.

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

json_decode() This function can also split the string into an array (the second parameter is true)

I believe you have mastered the method after reading the case in this article, please come for more exciting information Pay attention to other related articles on php Chinese website!

Recommended reading:

Summary of methods to prevent SQL injection in PHP

What are the methods for generating complex verification codes in PHP

The above is the detailed content of PHP operates string split into array. 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