Home  >  Article  >  Backend Development  >  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
WBOYOriginal
2016-07-21 15:00:27993browse

复制代码 代码如下:

/**
* @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 = '') { $...
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