Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between implode() & join()

Tags:

php

What is the difference between implode() & join() as both work the same way.

<?php     $array = array(1,2,3);          echo join(",", $array); // output 1,2,3     echo implode(",", $array); // output 1,2,3 ?> 

Is there is any advantage of using one over another?

like image 857
Khawer Zeshan Avatar asked Jul 28 '13 23:07

Khawer Zeshan


People also ask

What is the difference between implode () and explode () functions?

Difference between Implode and Explode function in PHPThe implode function works on an array. The explode function works on a string. The implode function returns string. The explode function returns array.

What is the use of implode () function?

The implode() is a builtin function in PHP and is used to join the elements of an array. implode() is an alias for PHP | join() function and works exactly same as that of join() function. If we have an array of elements, we can use the implode() function to join them all to form one string.

What is difference between implode join?

join appends the delimiter to the last element while implode doesn't.

Is implode and explode the same?

You can also convert between strings and arrays by using the PHP implode and explode functions: implode implodes an array to a string, and explode explodes a string into an array.


1 Answers

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%

like image 179
PlausibleSarge Avatar answered Sep 19 '22 21:09

PlausibleSarge