Implode and Explode in PHP
Implode and Explode in PHP

Implode and Explode in PHP there usage

Implode, Explode are commonly used functions in PHP. Implode is used to convert array values to a string. While passing parameter we can replace coma(,) by anything like space

Syntax

implode(separator,array)

Example

<?php 
$my_array=array("My","self","Junaid");
echo implode(' ',$my_array);
?>

The output of this example will be

My self Junaid

In the above example, we can see that all comas are replaced by space. we can use this function to a multi-selection option like a checkbox

Explode will help us to convert a string to an array using any separator. explode will help us to separate each value from a string to array value

Syntax

explode(separator,string,limit) 

Example

<?php 
$my_string="My self Junaid";
print_r (explode(" ",$my_string));
?>

Output

Array ( [0] => My [1] => self [2] => Junaid ) 

in the case of Explode, we can set a limit as the third parameter.

These two functions will help us when varus type of form action takes place for example

 <?php
$age_limit="18-22";
$ages=explode("-",$age_limit);
$age1=$ages[0];
$age2=$ages[1];

The output will be $age1 value will be 18 and $age2 value will be 22.

About the author

Junaid V J

My self Junaid . This Blog is a platform to gain immense knowledge of web development. Modern web designing and development can be acquired through this. Specialized in HTML, PHP, CSS, JAVASCRIPT , BOOTSTRAP,WORDPRESS, CODEIGNITER.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *