string http_build_query ( array formdata [, string numeric_prefix] );
有关下标的要加前缀,见PHP手册

解决方案 »

  1.   

            'color' => array('red', 'green', 'blue'),
    写作
            'color' => http_build_query(array('red', 'green', 'blue')),
    不行吗?写成这样更好
            'color[0]' => 'red',
            'color[1]' => 'green',
            'color[2]' =>  'blue',
      

  2.   

    <?php$post_url = "http://localhost/test/test1.php";
        $post_data = array(
            'a[1]' => 'red',
            'b[2]' => 'red',
            'c[3]' => 'red',
           
            'e[1]' => "@d:\img.gif",
            'e[2]' => "@d:\\2.gif"
        );
          
    //通过curl模拟post的请求;
    function SendDataByCurl($url,$data=array()){
        //对空格进行转义
        $url = str_replace(' ','+',$url);
        $ch = curl_init();
        //设置选项,包括URL
        curl_setopt($ch, CURLOPT_URL, "$url");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch,CURLOPT_TIMEOUT,3);  //定义超时3秒钟  
         // POST数据
        curl_setopt($ch, CURLOPT_POST, 1);
        // 把post的变量加上
        curl_setopt($ch, CURLOPT_POSTFIELDS, ($data));    //所需传的数组用http_bulid_query()函数处理一下,就ok了
        
        //执行并获取url地址的内容
        $output = curl_exec($ch);
        $errorCode = curl_errno($ch);
        //释放curl句柄
        curl_close($ch);
        if(0 !== $errorCode) {
            return false;
        }
        return $output;}
    $url = "http://localhost/test/test1.php";
    //通过curl的post方式发送接口请求
    echo  SendDataByCurl($url,$post_data);?>
      

  3.   

    output:
    Array
    (
        [a] => Array
            (
                [1] => red
            )    [b] => Array
            (
                [2] => red
            )    [c] => Array
            (
                [3] => red
            ))
    Array
    (
        [e] => Array
            (
                [name] => Array
                    (
                        [1] => img.gif
                        [2] => 2.gif
                    )            [type] => Array
                    (
                        [1] => application/octet-stream
                        [2] => application/octet-stream
                    )            [tmp_name] => Array
                    (
                        [1] => C:\Windows\Temp\php5C9E.tmp
                        [2] => C:\Windows\Temp\php5C9F.tmp
                    )            [error] => Array
                    (
                        [1] => 0
                        [2] => 0
                    )            [size] => Array
                    (
                        [1] => 43
                        [2] => 43
                    )        ))
      

  4.   

    xuzuning版主:
    使用
            'color[0]' => 'red',
            'color[1]' => 'green',
            'color[2]' =>  'blue',
    这样的方式是可以的,感谢你的提醒,使我再次确认了一下代码。这样的方式与我提到的那位php.net网友做法一致,无论关联数组或者索引数组都是一样可以行的。用 'color' => http_build_query(array('red', 'green', 'blue'))这样应该是不行的,从服务器抓到的数据来看,color的值变成了类似0=red&1=green&2=blue这样的结构,预期的应该是数组值。
    conqweal:
    谢谢你的热心帮助,确实如你代码所示,只要按照这样组织代码就可以了。
    感谢各位
      

  5.   

    <?php echo 111111 ?>