Skip to content
PHP Logo

How can the explode function be used to split a string into arrays in PHP?

The explode function in PHP can be used to split a string into an array based on a specified delimiter. This can be useful when you need to separate a string into individual elements for further processing or manipulation. To use the explode function, simply provide the string to be split and the delimiter as arguments, and it will return an array of substrings.

php
$string = "apple,banana,orange";
$fruits = explode(",", $string);

print_r($fruits);