Home > Article > Backend Development > PHP implementation code to convert POST data into string
The main purpose is to record the parameters of POST;
The main principle of the following functions is to use recursion to convert multi-dimensional arrays into one-dimensional arrays. Finally, the array can be converted to string processing to get the POST. Data stringification;
Core code:
/** * 应用于LOG记录POST参数使用 * * @version 0.0.1 * @Author Chenjl <ciwdream@gmail.com> * * @return string */ function getPostLog(array $_data = array(),$n = ''){ $_gPOST = empty($_data) ? I('post.') : $_data; $_rs = array(); foreach ($_gPOST AS $name=>$value){ if( is_array($value) ){ $_rs[] = getPostLog($value,$name); }else{ if( !empty($_data) ){ $_rs[] = $n.'['.$name.']'.'='.$value; }else{ $_rs[] = $name.'='.$value; } } } $_rs = implode('&', $_rs); return $_rs; }
Complete
More PHP converts POST data into For articles related to string implementation code, please pay attention to the PHP Chinese website!