PHP join function

 The function of the PHP join function is to combine the array elements in the PHP Array into a string, and the effect is the same as the implode function. For example, we store the data retrieved from the database in an array, and output a complete word String, you can use the join function to combine each array element in the array. The PHP join function allows you to set the combined characters yourself. According to the documentation on the PHP official website, the PHP join function is an alias of the implode function, in other words , These two functions are actually the same, but with the development of the PHP version, there is a little difference in the use of parameters between the two. This article focuses on the basic application of the join function.


PHP join function syntax
join(combining characters, Array);
The PHP join function has two parameters that can be used. The first parameter "combining characters" is an optional item, and the default value is empty, that is, each array element will be glued together after forming a string. If you want to use other symbol strings Even, such as spaces, English letters or punctuation marks, can be set here. The second parameter Array of the join function is the array to be processed and is required.

PHP join function example
<?php
$MyArray=array('Welcome','to','Wibibi.');
echo join('',$MyArray).'<br>';
echo join('',$MyArray).'< br>';
echo join('-',$MyArray).'<br>';
?>
Example output
WelcometoWibibi.
Welcome to Wibibi.
Welcome-to-Wibibi.
At the beginning of the example, a simple PHP one-dimensional array $MyArray is prepared. There are three array elements in total. Then the join result is output through three echoes . The main difference lies in the use of the first parameter of the join function. If it is not used The first parameter, the join function, will glue all the strings together. The designer can decide which characters to use to connect the strings. This function is actually the same as the implode function.

➤Research on the same function as the PHP join function: PHP implode

Post a Comment

0 Comments