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

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

WBOY
Release: 2016-06-13 11:28:37
Original
792 people have browsed it

    <span /*</span><span *
     * @desc    多维数组转化为支持curl提交数组
     * @author    lytian    2013-06-29
     </span><span */</span>
    <span public</span> <span function</span> toPost(<span array</span> <span $params</span> = <span array</span>(), <span $pre</span> = ''<span )
    {
        </span><span $result</span> = <span array</span><span ();
        </span><span foreach</span> (<span $params</span> <span as</span> <span $key</span> => <span $val</span><span )
        {
                </span><span if</span> (<span is_array</span>(<span $val</span><span ))
                {
                    </span><span $subPre</span> = (<span $pre</span>=="") ? <span $key</span> : <span $pre</span> . "[" . <span $key</span> . "]"<span ;
                    </span><span //</span><span $pre = "[" . $key . "]";</span>
                    <span $result</span> = <span array_merge</span>(<span $result</span>, toPost(<span $val</span>, <span $subPre</span><span ));
                    
                }
                </span><span else</span><span 
                {
                    </span><span $result</span>[<span $pre</span>."[".<span $key</span>."]"] = <span $val</span><span ;
                }
        }

        </span><span return</span> <span $result</span><span ;
    }</span>
Copy after login

 

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