manhgame1
Raid Leader
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 2
1000 XP
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.
What is implode() in PHP?
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.
How to use PHP implode() function?
<?php
implode
(
str $seperator
,
array
$array
)
?>
Parameters
Example
Here is an example snippet that demonstrates the usage of implode() function of PHP.
Result
What is explode() in PHP?
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.
How to use PHP explode() function?
Parameters
Example
Here is an example snippet that demonstrates the usage of explode() function of PHP.
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.
Happy Coding :)
Download
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.
What is implode() in PHP?
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.
How to use PHP implode() function?
<?php
implode
(
str $seperator
,
array
$array
)
?>
Parameters
- (str)$seperator
- The string that is placed between the array items when combined.
- The string that is placed between the array items when combined.
- (arr)$array
- The array of strings to combine or implode.
- The array of strings to combine or implode.
Example
Here is an example snippet that demonstrates the usage of implode() function of PHP.
- <?php
- //Sample Arrays
- $array1
=
array
(
"Hello"
,
"Wold!!!"
)
;
- $array2
=
array
(
"I"
,
"Love"
,
"SourceCodester!"
)
;
- $array3
=
array
(
"PHP"
,
"JavaScript"
,
"Python"
)
;
- //Combining Arrays
- $arrtostring1
=
implode
(
" "
,
$array1
)
;
- $arrtostring2
=
implode
(
" "
,
$array2
)
;
- $arrtostring3
=
implode
(
", "
,
$array3
)
;
- echo
$array1
.
"<br>"
;
- echo
$array2
.
"<br>"
;
- echo
$array3
;
- ?>
Result
What is explode() in PHP?
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.
How to use PHP explode() function?
- <?php
explode
(
str $seperator
,
str $string
,
int $limit
delault:
PHP_INT_MAX)
?>
Parameters
- (str)$seperator
- The string checks and serves as the boundaries of the items for splitting.
- The string checks and serves as the boundaries of the items for splitting.
- (str)$string
- The string to split using the method/function.
- The string to split using the method/function.
- (int)$limitDefault:
PHP_INT_MAX
- The limit count of the result's return array items and if the entered value is positive.
- If negative, the function will return all the items except the last (n) item/s.
- The limit count of the result's return array items and if the entered value is positive.
Example
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"
;
- $splitString1
=
explode
(
" "
,
$string1
)
;
- $splitString2
=
explode
(
" "
,
$string2
)
;
- $splitString3
=
explode
(
", "
,
$string3
,
-
1
)
;
- print_r
(
$splitString1
)
;
- echo
"<br>"
;
- print_r
(
$splitString2
)
;
- echo
"<br>"
;
- print_r
(
$splitString3
)
;
- ?>
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.
Happy Coding :)
Download
You must upgrade your account or reply in the thread to view the hidden content.