join an array of characters into a string in php

To join an array of characters into a string in PHP, you can use the implode() function.

The implode() function takes two parameters:

  • the first parameter is the separator that you want to use to join the array elements.
  • the second parameter is the array that you want to join.

Here's an example:

main.php
$array = array('H','e','l','l','o');
$string = implode('', $array);
echo $string;
82 chars
4 lines

This will output:

main.php
Hello
6 chars
2 lines

In the example above, we used an empty string as the separator, but you can use any string you want to separate the elements. If the separator string is not provided, the default separator is an empty string.

related categories

gistlibby LogSnag