Home > Backend Development > PHP Tutorial > Parse and convert a multi-dimensional array into a one-dimensional array format that supports curl submission_PHP tutorial

Parse and convert a multi-dimensional array into a one-dimensional array format that supports curl submission_PHP tutorial

WBOY
Release: 2016-07-21 15:00:27
Original
1009 people have browsed it

复制代码 代码如下:

/**
* @desc Multi-dimensional array is converted into an array that supports curl submission
* @author Script Home 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;
    }

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/328058.htmlTechArticle复制代码 代码如下: /*** @desc Multi-dimensional array is converted into an array that supports curl submission * @author Script House 2013-07-8*/ public function toPost(array $params = array(), $pre = '') { $...
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