Home > Backend Development > PHP Tutorial > 解析将多维数组转换为支持curl提交的一维数组格式_php技巧

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

WBOY
Release: 2016-05-17 08:56:54
Original
963 people have browsed it

复制代码 代码如下:

/**
     * @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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template