What is the purpose of the explode function in PHP?
The explode function in PHP is used to split a string into an array based on a specified delimiter. This can be useful when you have a string that contains multiple values separated by a common character, such as a comma or space, and you want to extract each value individually. By using the explode function, you can easily parse and manipulate the different parts of the string as needed. Example:
$string = "apple,banana,orange";
$fruits = explode(",", $string);
foreach ($fruits as $fruit) {
echo $fruit . "<br>";
}