Forums

PHP

This topic is locked

Is it possible to convert the array to string?

Posted 26 Dec 2011 12:22:01
1
has voted
26 Dec 2011 12:22:01 phiehgch phiehgch posted:
Hello,
I want to convert dimensional array to string and saved in to a file.Also need to convert string that stored in the file to the previous array for further processing. Is it possible to convert the array to string and then back to array using php?
If anyone knows please help me thanks in advance.

Replies

Replied 26 Mar 2012 12:30:20
26 Mar 2012 12:30:20 Roddy Dairion replied:
Using the implode() function for a 1 dimensional array you should be able to achieve what you want to do e.g.

$arr=array("John","Joe","Smith");
echo implode(",",$array);


For a multidimensional array using a foreach loop should do the trick


$arr=array("John"=>"Doe","Joe"=>"Black","Smith"=>"Walker");
foreach($array as $key=>$value){
    $string.="Firstname is ".$key." surname is ".$value.",";
}
echo rtrim($string,',');


Hope this help. Question is now what is are you trying to achieve?

Roddy.

Reply to this topic