The explode() function is used to split a string.

sometimes required to convert string into php array. I'll tell how to use it with examples PHP explode().

explode() function used when we need to split a string using a specific character or string present in that string.

Syntax

explode(separator,string,limit)

The "separator" and "string" parameter cannot be an empty string.

The limit parameter is an Optional. Specifies the number of array elements to return.

See below example

<?php

$data="Hello world. It's a beautiful day.";
$split=explode(" ",$data);

foreach ($split as $key => $value) 
{
	echo "split[".$key."] = ".$value."<br>";
}


//output

// split[0] = Hello
// split[1] = world.
// split[2] = It's
// split[3] = beautiful
// split[4] = day.

?>