PHP implementation code to convert POST data into string

高洛峰
Release: 2023-03-04 10:12:01
Original
2220 people have browsed it

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;
}
Copy after login

Complete

More PHP converts POST data into For articles related to string implementation code, please pay attention to the PHP Chinese website!

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!