PHP explode() function with foreach loop

PHP explode() :

The explode() function breaks a string into an array.

Syntax : explode(separator,string,limit)

Parameter Description:

separator —-Required. Specifies where to break the string

string ———Required. The string to split

limit ———-Optional Specifies the maximum number of array elements to return

Example of PHP explode:

<?php
$var= “Gmail is built on the idea “;

$pieces = explode(” “, $var);
foreach($pieces as $element)
{
echo $element.”<br/>”;
}

?>

Output:

Gmail
is
built
on
the
idea

Leave a comment