PHP explode() Function

The explode() function breaks a string into an array.

Note: The “separator” parameter cannot be an empty string.

The explode() function space string into an array.

The explode() function comma separated a string into an array.

$string = "9,8,7,abc";
$array = explode(',', $string);
print_r($array);

Output

Array
(
    [0] => 9
    [1] => 8
    [2] => 7
    [3] => abc
)

Another Example

$string = "9 8 7 abc";
$array = explode(' ', $string);
print_r($array);

Output

Array
(
    [0] => 9
    [1] => 8
    [2] => 7
    [3] => abc
)

Leave a Reply

Your email address will not be published. Required fields are marked *