Although implode() can, for historical reasons, accept its parameters in either order, explode() cannot. Why?
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
is similar to
$array = array('lastname', 'email', 'phone');
$comma_separated = implode( $array,",");
Why?
As per implode() and explode() documentation, they only said it's historical reason.
This is what found in quora. Also the reason sounds promising!!
Part of the reason, I guess, is that both parameters of explode are strings, thus it would be difficult to tell which is the delimiter and which is the original string if they're swapped. Implode, however, takes a string (glue) and an array (pieces) as its parameters. It's at least easy to tell them apart.
The 'historical reason' might refer to an API design guideline change, where it was decided that 'smaller' parameters (needle, glue) should be before 'bigger' parameters (haystack, pieces). Implode might have used the reverse order before that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With