Home >Backend Development >PHP Tutorial >PHP implementation code to convert POST data into string

PHP implementation code to convert POST data into string

高洛峰
高洛峰Original
2016-12-26 14:07:152282browse

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 = &#39;&#39;){
 $_gPOST = empty($_data) ? I(&#39;post.&#39;) : $_data;
 $_rs = array();
 foreach ($_gPOST AS $name=>$value){
  if( is_array($value) ){
   $_rs[] = getPostLog($value,$name);
  }else{
   if( !empty($_data) ){
    $_rs[] = $n.&#39;[&#39;.$name.&#39;]&#39;.&#39;=&#39;.$value;
   }else{
    $_rs[] = $name.&#39;=&#39;.$value;
   }
  }
 }
 $_rs = implode(&#39;&&#39;, $_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!

Statement:
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