首頁 > 後端開發 > php教程 > 将多维数组转换为支持curl提交的一维数组格式_PHP教程

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

WBOY
發布: 2016-07-20 11:12:43
原創
728 人瀏覽過

    <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>
登入後複製

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440428.htmlTechArticletoPost( = (), = '' = ( = ( ( = ( =="") ? : . "[" . . "]" = ( , toPost( , [ ."[". ."]"] =...
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板