convert string in to array and array to string using php

When we are working with the PHP then we need to convert the array elements in to string and string in to array elements, below is the some useful library function which we can use in php.

1) explode function is used to split a string by string.

Syntax : array explode ( string $delimiter , string $string [, int $limit ] )

Example Explode function

 
<?php
 
$str = 'php freelancer | freelancer php | php developer | hire php developer | hire php freelancer | freelancer india';
$arr = explode('|',$str);
echo "<pre>";
print_r($arr);
 
<strong>Output</strong>
 
Array
(
[0] => php freelancer
[1] => freelancer php
[2] => php developer
[3] => hire php developer
[4] => hire php freelancer
[5] => freelancer india
)
 
?>

2) implode function is used to Join array elements with a string.

Syntax : string implode ( string $glue , array $pieces )

Example Implode function

 
<?php
$arr = Array('php freelancer','freelancer php','php developer','hire php developer','hire php freelancer','freelancer india');
 
$str = implode('|',$arr);
echo $str;
 
<strong>Output</strong>
 
php freelancer | freelancer php | php developer | hire php developer | hire php freelancer | freelancer india
 
?>