What is the difference between IMPLODE & JOIN

Can't think of any. The one is an alias of the other. They both combine array elements into a string.


join() is an alias for implode(), so implode is theoretically more "PHP native" though there is absolutely no performance increase to be gained by using it.

On the other hand, join() is found in, amongst other languages, Perl, Python and ECMAScript (including JavaScript) and so is much more portable in terms of comprehensibility to a wider audience of programmers.

So although explode and implode are unarguably way more dramatic-sounding, I would vote for join as a more universal way to express the concatenation of every value of an array into a string.


Join: Join is an Alias of implode().

Example:

<?php
$arr = array('Test1', 'Test2', 'Test3');
$str = join(",", $arr);
echo $str; 
?>

Output: Test1,Test2,Test3.

Implode: implode Returns a string from array elements.

Example:

<?php
$arr = array('Test1', 'Test2', 'Test3');
$str = implode(",", $arr);
echo $str; 
?>

Output: Test1,Test2,Test3.

UPDATE:

I tested them in Benchmark and they are same in speed. There is no difference between them.


They are aliases of each other. They should theoretically work exactly the same. Although, using explode/implode has been shown to increase the awesomeness of your code by 10%

Tags:

Php