##PHP
provides us with the explode()
function. This article will take you to take a look. First of all, the first thing that should be understood should be the syntax:
explode ( string $delimiter,string $string , int $limit = ? )
1. When using two parameters: <?php
$sentence1 = "良人当归即好,人生当苦无妨,我有一剑,可搬山";
$sentence2 = explode(",", $sentence1);
print_r($sentence2);
输出:Array( [0] => 良人当归即好 [1] => 人生当苦无妨 [2] => 我有一剑 [3] => 可搬山)
2. When there are three parameters used: 《2021 PHP interview questions summary (collection)》《php video tutorial》 The above is the detailed content of Detailed explanation of the explode() function in PHP. For more information, please follow other related articles on the PHP Chinese website!<?php
$sentence1 = "良人当归即好,人生当苦无妨,我有一剑,可搬山";
//$limite为正整数
$sentence2 = explode(",", $sentence1,3);
print_r($sentence2);
echo "<br>";
//$limite为0
$sentence3 = explode(",", $sentence1,0);
print_r($sentence3);
echo "<br>";
//$limite为负整数
$sentence4 = explode(",", $sentence1,-2);
print_r($sentence4);
输出:
Array( [0] => 良人当归即好 [1] => 人生当苦无妨 [2] => 我有一剑 [3] => 可搬山)
Array( [0] => 良人当归即好,人生当苦无妨,我有一剑,可搬山)
Array( [0] => 良人当归即好 [1] => 人生当苦无妨)