Function code in PHP to convert an array into a string and save it to the database_PHP Tutorial

WBOY
Release: 2016-07-21 16:13:07
Original
962 people have browsed it

Copy code The code is as follows:

/**
* Convert string to array
*
* @param string $data String
* @return array Return array format, if data is empty, return empty array
*/
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
* @return string Returns a string, if data is empty, then returns empty
*/
function array2string($data, $isformdata = 1) {
if($data == '') return '';
if($isformdata) $data = new_stripslashes($data);
return addslashes(var_export($data, TRUE));
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/313526.htmlTechArticleCopy the code code as follows: /*** Convert the string to an array * * @param string $data string * @return array Returns the array format, if data is empty, returns an empty array*/ func...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template