How to use implode in PHP

In this article I will explain how the implode() function can be used in PHP.
  • 1565

implode() function in PHP

  • The implode() function is used to return a string from the elements of an array.
  • The implode() function is used to join array elements with a string.
  • The implode() function returns a string by joining all the array elements together specifies by the separator.
  • The separator parameter of implode() is optional.

Syntax

implode(separator,array)

Parameter

  • separator separator is required parameter. separator puts between the array elements, the default value is an empty string.
  • array array is optional parameter. array to join into string.

Example

The following example show to how the implode() function can be used in PHP.

<html>

<body>

<h3 style="color: darkblue;">implode() function example in PHP</h3>

    <?php

    $array=array('C', 'sharp', 'corner');

    echo"Apply impode function with '-' <br/>";

    $join_string=implode("-", $array);

    echo $join_string;

    echo '<br>';

    echo"Apply impode function with space <br/>";

    $join_string=implode(" ", $array);

    echo $join_string;

    ?>

</body>

</html>

 

Output

implode-php.gif
You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.