PHP array saves text and text is decoded into array instance,
The example in this article describes the method of saving text in a php array and decoding the text into an array. Share it with everyone for your reference. The specific implementation method is as follows:
The following example defines two functions, string2array is used to convert a string into an array, and array2string is used to convert an array into a string.
The specific implementation code is as follows:
Copy code The code is as follows:
function string2array($data) {
if($data == '') return array();
@eval("$array = $data;"); return $array;
}
/**Convert array to string
* @param array $data array
* @param bool $isformdata If it is 0, new_stripslashes processing is not used, optional parameter, default is 1
* string Returns a string, if data is empty, returns empty*/
function array2string($data, $isformdata = 1) {
if($data == '') return '';
if($isformdata) $data = new_stripslashes($data);
return addslashes(var_export($data, TRUE));
}
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/910586.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/910586.htmlTechArticlePHP array saves text and text is decoded into an array example. This example describes how PHP array saves text and text is decoded array method. Share it with everyone for your reference. Specific implementation method...