join an array of substrings into a string in php

To join an array of substrings into a string in PHP, you can use the implode function. The implode function takes two arguments - the delimiter to separate the substrings with and the array of substrings to join.

Here's an example:

main.php
$substrings = array('Hello', 'world', '!');
$string = implode(' ', $substrings); // separate substrings with a space
echo $string; // output: "Hello world !"
158 chars
4 lines

In this example, we create an array of substrings, then use the implode function to join them into a string with spaces between each substring. The resulting string is then echoed out.

related categories

gistlibby LogSnag