I have a function like this:
function array2string($data) {
if($data == '') return '';
return addslashes(var_export($data, TRUE));
}
I invoke this function convert $_REQUEST Array to String just like
array2string($_REQUEST)
and convert the result String to Array use this function:
function string2array($data) {
// print_r($data);
$data=str_replace('\'',"'",$data);
// $data=str_replace(''',"'",$data); // add by futan 2015-04-28
$data=str_replace("\'","'",$data);
// print_r($data);exit();
if($data == "") return array();
@eval("\$array = $data;");
return $array;
}
Generally, it can work, bur sometimes,it doesn't work.
the result like this:
array ( \'name\' => \'xxx
I cant find any problem, because I cant recurrence error. someone can help me??
serialize()andunserialize()instead if you want string representation of the array data and vice versa.json_encodeandjson_decode.serialize()for that purpose. I will post an answer shortly.