PHP implode

 The PHP implode function can combine the array elements of PHP Array into a new string, and according to the needs of the system or design, you can set the string characters in series by yourself, showing the characteristic string content, which is converted by the implode function Strings, do not need print_r or loop output, you can directly use echo to output to the web page.


PHP implode basic syntax

string implode (string hyphen, $array) or string implode ($array)


The first parameter "concatenation character" of the implode function has been changed to select items since PHP 4.3.0. In other words, it is fine to not write, but if you do not write, each array element will be directly stringed together. In the following example, you can see the rendering results. The second parameter $array must be written, which is the original array to be converted.

PHP implode example
<?php
$new_array = array('Welcome','to','Wibibi.');
echo implode($new_array).'<br>';
echo implode('',$new_array).'<br>' ;
echo implode('-',$new_array);
?>
The above example presents the results
WelcometoWibibi.
Welcome to Wibibi.
Welcome-to-Wibibi.
From the output result, we can see that the first parameter of the implode function is not filled in, and the entire array elements are stringed together to become an unintelligible English string. In the second output, we used blanks as concatenated characters. It becomes an understandable English sentence, and the last output is the effect of concatenating with the "-" symbol. You can modify it according to the needs of the program at that time.

Post a Comment

0 Comments