Hello Readers,
In this blog, I am going to tell a small difference between Explode & Split function in PHP. Both the function do the same thing i.e split a string into array.
But there is a minor difference that explode takes delimiter to split while split takes regular expression. This means the running time of explode is faster than split function.
According to PHP Documentation : preg_split() is faster than split(), so really there isn’t much of a reason to use split() at all.
Example of Explode() Function
<?php
$str = "welcome to Find Nerd";
print_r (explode(" ",$str)); // split a string by string into array
?>
Output: Array ( [0] => welcome [1] => to [2] =>Find [3] => Nerd)
Example of Split() Function
<?php
$str = "w.t.f.n"
print_r(split ("\.", $str)); // split a string into array using regular expression.
?>
Output: Array ( [0] => w [1] => t [2] => f [3] => n )
0 Comment(s)