Split string into array

php中世界最好的语言
Release: 2023-03-22 09:18:02
Original
3425 people have browsed it

This time I will bring you StringSplit into array, what are the precautions for splitting a string into an array, the following is a practical case, one Get up and take a look.

The example is as follows:

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

Split $str by |

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

str_split(string,length)
Copy after login

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:

php retains key value + detailed explanation of merging arrays

How to reset the array to a numeric index

The above is the detailed content of Split string into array. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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