How can explode() function be used to convert a string of names into an array in PHP?

The explode() function in PHP can be used to convert a string of names into an array by specifying the delimiter that separates each name in the string. By using explode() with the delimiter as a space, comma, or any other character that separates the names, the function will split the string into an array where each element is a name.

// String of names
$names = "John, Jane, Bob, Alice";

// Convert string into an array using explode()
$namesArray = explode(", ", $names);

// Output the array of names
print_r($namesArray);