In this article, you will learn how to use the PHPs implode() and explode() built-in functions. The tutorial aims to provide the IT/CS students and new programmers a reference for widening their knowledge and enhancing their PHP Programming capabilities. Here, snippets that demonstrate the usage of the said PHP functions are provided.
PHP comes with built-in methods and functions that are helpful and useful for developers to achieve their desired features for their projects or web applications. The implode() and explode() functions are one of these and are available from PHP version 4 up to the latest which is PHP8. These functions are used for manipulating arrays and strings.
The implode() function in PHP is a built-in function that allows you to combine the array of data into one string. Developers can simply join the array items and set a string between each item.
<?php implode(str $seperator, array $array) ?>
Here is an example snippet that demonstrates the usage of implode() function of PHP.
<?php //Sample Arrays //Combining Arrays echo $array1."<br>"; echo $array2."<br>"; echo $array3; ?>
Result
The explode() function in PHP is a built-in function that allows you to split the string into pieces. The developers can explode the string using the given separator. The explode function result can be limited depending on the developer's given count of items to return.
Here is an example snippet that demonstrates the usage of explode() function of PHP.
<?php $string1 = "Hello Wold!!!"; $string2 = "I Love SourceCodester!"; $string3 = "PHP, JavaScript, Python"; echo "<br>"; echo "<br>"; ?>
Result
There you go! I hope this Usage of PHPs implode() and explode() built-in function tutorial helps you and enhances your programming knowledge and capabilities.
Explore more on this website for more Tutorials and Free Source Codes.