Explode () function: Splits the array by splitting another string with one string. The following article introduces you to the use of PHP explode () function cut string array, the need for friends can refer to the following
Explode () function: Splits the array by splitting another string with one string.
For example:
String
$pizza = "1th 2nd 3rd 4th 5th 6th";
After dividing by space:$pieces = explode(” “, $pizza);
$pieces is the segmented array, we print it out to see
<?php$pizza = "1th 2nd 3rd 4th 5th 6th"; $pieces = Explode ("", $pizza); foreach ($pieces as $val) { echo $val. " <br> ";} Piece1piece2piece3piece4piece5piece6
Example 2: Segmentation by commas
<?php$string = ' The sun is very big today, we have not gone out. At noon we eat in the canteen, are very happy! '; $string _arr = Explode (",", $string); foreach ($string _arr as $val) { echo $val. " <br> ";}
Output Result:
The sun is very big today
None of us have gone out. We'll eat in the cafeteria at noon.
All very happy!