Convert String to Array in PHP Explode

In PHP, the explode function can be used to convert a string into an array. The explode function splits the string into individual elements in the array based on a specified delimiter.

Here is a sample code:

$str = "apple,banana,orange";
$array = explode(",", $str);
print_r($array);

The output is:

Array
(
    [0] => apple
    [1] => banana
    [2] => orange
)

In the example above, we split the string “apple,banana,orange” using a comma as a separator into an array containing three elements.

bannerAds