Home > php教程 > php手册 > 解析将多维数组转换为支持curl提交的一维数组格式

解析将多维数组转换为支持curl提交的一维数组格式

WBOY
Release: 2016-06-06 20:28:30
Original
1275 people have browsed it

本篇文章是对将多维数组转换为支持curl提交的一维数组格式实现代码进行了详细的分析介绍,需要的朋友参考下

复制代码 代码如下:


/**
     * @desc    多维数组转化为支持curl提交数组
     * @author    脚本之家    2013-07-8
     */
    public function toPost(array $params = array(), $pre = '')
    {
        $result = array();
        foreach ($params as $key => $val)
        {
                if (is_array($val))
                {
                    $subPre = ($pre=="") ? $key : $pre . "[" . $key . "]";
                    //$pre = "[" . $key . "]";
                    $result = array_merge($result, toPost($val, $subPre));

                }
                else
                {
                    $result[$pre."[".$key."]"] = $val;
                }
        }

        return $result;
    }

,香港空间,服务器空间,服务器空间
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template