Skip to content
PHP Logo

What PHP function can be used to split a string into an array based on a delimiter?

To split a string into an array based on a delimiter in PHP, you can use the `explode()` function. This function takes two parameters: the delimiter (the character or characters on which to split the string) and the string to be split. It returns an array of substrings.

php
$string = "apple,banana,cherry";
$delimiter = ",";
$array = explode($delimiter, $string);

print_r($array);