Array ( [0] => A [1] => E )
i want the above array values to be converted to string.please help
Use implode() function of php:
The implode()
function returns a string from the elements of an array.
It takes 2 arguments:
implode(separator,array)
separator Optional. Specifies what to put between the array elements. Default is "" (an empty string) array Required. The array to join to a string
check: http://php.net/manual/en/function.implode.php
$array = array("A","E");
$str = implode("",$array);
echo $str;
Output:
AE
just write this one line code
$a = array_map('strval', $a);
use IMPLODE() function
The implode() function returns a string from the elements of an array.
$ss= Array ( 0 => 'A', 1 => 'E' );
$sss =implode('',$ss);
echo $sss;
?>
OUTPUT: AE
Use serialize()
for array to string conversion. And use unserialize()
to convert string to array again.
<?php
$array = ['A','B','C'];
$arrayToString = serialize($array); //a:3:{i:0;s:1:"A";i:1;s:1:"B";i:2;s:1:"C";}
echo $arrayToString;
$stringToArray = unserialize($arrayToString);
var_dump($stringToArray);