implode(): Join elements of array to get string

$ar=array('Welcome','to','plus2net','php','section');
echo implode($ar);
The output is here
Welcometoplus2netphpsection
Sorry , we missed the space between words so let us add one gap between
$ar=array('Welcome','to','plus2net','php','section');
echo implode(" ",$ar);
The output is here
Welcome to plus2net php section

Example 1: Joining Array Elements with a Custom Separator

<?php
$ar = array('apple', 'banana', 'cherry');
echo implode(" - ", $ar);  // Output: apple - banana - cherry
?>

Example 2: Imploding with Empty Strings

<?php
$ar = array('P', 'H', 'P');
echo implode("", $ar);  // Output: PHP
?>

Example 3: Joining Elements from an Associative Array

<?php
$ar = array('name' => 'John', 'age' => 25);
echo implode(", ", $ar);  // Output: John, 25
?>

Example 4: Imploding Multi-Dimensional Arrays

<?php
$multi_array = array(array('a', 'b'), array('c', 'd'));
foreach($multi_array as $arr) {
    echo implode(", ", $arr) . "<br>";  // Output: a, b and c, d on new lines
}
?>

Example 5: Handling Empty Arrays with implode()

<?php
$empty_array = array();
echo implode(", ", $empty_array);  // Output: (empty string)
?>

String Functions explode(): Array from string
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer