Monday, May 12, 2014

difference between Split and Explode in PHP

The split() function splits the string into an array using a regular expression and returns an array.


The explode() function splits the string by string.
Ex:
    $split_array=split(':','India:Pakistan:Srilanka');

    $explode_array=split('and','India and Pakistan and Srilanka');

    print_r($split_array);

    print_r($explode_array);
?>
The result will be
Array ( [0] => India [1] => Pakistan [2] => Srilanka )
Array ( [0] => India [1] => Pakistan [2] => Srilanka )