implode() function in PHP


The implode() function is used to join array elements with a string.

Syntax

implode(separator, arr)

Parameters

  • separator − Specifies what to include between the array elements. The default is ""

  • arr − The array to join to a string

Return

The implode() function returns a string from elements of an array.

Example

The following is an example −

 Live Demo

<?php
   $arr = array('This','is','Demo','Text!');
   echo implode("$",$arr);
?>

Output

The following is the output −

This$is$Demo$text!

Example

The following is an example −

 Live Demo

<?php
   $myarr = array('This','is','Demo','Text!');
   echo implode("-",$myarr);
   echo implode("#",$myarr);
?>

Output

The following is the output −

This-is-Demo-Text!This#is#Demo#Text!

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Dec-2019

68 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements