1Definition and Usage
2The join() function returns a string from the elements of an array.
3
4The join() function is an alias of the implode() function.
5
6Note: The join() function accept its parameters in either order. However, for consistency with explode(), you should use the documented order of arguments.
7
8Note: The separator parameter of join() is optional. However, it is recommended to always use two parameters for backwards compatibility.
9
10Syntax
11join(separator,array)
12
13Example
14Join array elements with a string:
15
16<?php
17$arr = array('Hello','World!','Beautiful','Day!');
18echo join(" ",$arr);
19?>
20
21Output:
22Hello World! Beautiful Day!
1<?php
2// implode ( string $separator , array $array )
3
4$res = implode ( ",", $array );
5
6?>
1
2$array1 = [1, 5, 64, 2, 6];
3$array2 = [2, 1, 8, 3];
4
5//Method 1:
6array_filter($array1, function($_){
7 global $array2;
8 return in_array($_, $array2);
9}); // Output: [0 => 1, 3 => 2]
10
11//Method 2:
12array_intersect($array1, $array2); //Output: [0 => 1, 3 => 2]
13
1Combina los elementos de uno o más arrays juntándolos de modo que los valores de uno se anexan al final del anterior. Retorna el array resultante.