比如:<?php   $data = array("red", "org", "yel", "green");?><html>
<head>
</head>
<body>
<center>
 
      就是这么个意思吧,我怎么把data 这个数组让  test.php 使用? 
    <a href = test.php?xxx= $data>  ssss </a></center>
</body></html

解决方案 »

  1.   

    echo http_build_query(array("red", "org", "yel", "green"));out:
    0=red&1=org&2=yel&3=green再怎么做,你用该知道了
      

  2.   

    我只能把数组的每个项分开使用吗?<a href = test.php?0=red&1=org&2=yel&3=green >是这样吗?有什么简单的方法吗?如果我数组项很多,那怎么弄?
      

  3.   


       数组当函数的参数怎么用呀?<?php  $data = array("red", "org", "yel", "green");   EchoTLPic($data);   可以直接这么用吗?
    ?> 
      

  4.   


    <?php  $data = array("red", "org", "yel", "green");     function echoarray($data)
        {
            foreach($data as $c)
            {
                while(list($k, $c) = each($c))
                {
                    echo "$k  ==> $c <br/>";
                }
            }
        }
       echoarray($data);
       
    ?>
    显示错误是这个怎么解决呀?
    Warning: Variable passed to each() is not an array or object in /var/www/CreatTrendLine.php on line 45Warning: Variable passed to each() is not an array or object in /var/www/CreatTrendLine.php on line 45Warning: Variable passed to each() is not an array or object in /var/www/CreatTrendLine.php on line 45Warning: Variable passed to each() is not an array or object in /var/www/CreatTrendLine.php on line 45
      

  5.   

    $data = array("red", "org", "yel", "green"); 
    function EchoTLPic($test)
    {
    print_r($test);
    }
    EchoTLPic($data);
      

  6.   


    $data = array("red", "org", "yel", "green");
    echo '<a href="test.php?xxx=', base64_encode(serialize($data)), '">xxx</a>';$data = unserialize(base64_decode($_GET['xxx']));//获得数组但是URL长度是有限制的,所以数组不能太大。
      

  7.   

    print_r($test);   打印确实能够打印,就是说我真没传参数是对的?是吗?但是在函数内我怎么遍历每个成员呢?我只是想打印呀?
      

  8.   

    很奇怪,http_build_query 是php5的内置函数,正是为了解决你的问题而设立的
    完全没有必要去写什么 EchoTLPic、echoarray 等无聊的函数或做什么编码解码
      

  9.   


        function echoarray($data) 
        { 
            foreach($data as $k => $c) 
            {                 echo "$k  ==> $c <br/>";         } 
        } 
      

  10.   

     不好意思,刚看 PHP ,边学边做。查了下,http_build_query() 函数的作用,
    http_build_query函数是PHP5加入的,作用就是把数组或对象转换成URL的querystring。
    平时我们做URL的GET请求时做的querystring是把一个一个的键值连接到一块儿,
    这样的话,如果只有三四个还好,多了就不行了。一维数组确实是这样:        foreach($data as $k => $c)
            {                echo "$k  ==> $c <br/>";        } 二维呢?
    比如:    $data =  array(
            array("red", "org", "yel", "green"),
            array("red", "org", "yel", "green"), 
            array("red", "org", "yel", "green"), 
            array("red", "org", "yel", "green")
        );
    这个函数中怎么写呢?谢谢了!
        function echoarray($data1)
        {
        }
      

  11.   

    汗,二维的我这么做的。        foreach($data1 as $k => $c)
            {
                foreach($c as $e => $u)
                {
                    echo "$e  ==> $u <br/>";
                }
                //echo "$k  ==> $c <br/>";
            }   
      

  12.   

    为啥这么不行呢?        for($i =0, $num = count($data1); $i < $num; $i++)
            {
                $data2 = $data1[i];
                for($j =0, $num2 = count($data2); $j < $num2; $j++)
                {
                    echo " ==> $data2[$j] <br/>";
                }
            }
      

  13.   

    请重新考虑你是否需要传递一个数组。
    如果这个数组是固定的,你可以将数组保存在单独的一个文件里,然后让所有需要用的程序include一下。
    如果某一页需要用这个数组的第3个数据,前一页只需要把3传递过去就可以了。
    GET方式下(一种是表单method是GET,一种就是在URL地址里传值),数据长度是有限制的,至少,比POST方式要少得多。
      

  14.   

    为什么不能直接include。传来传去的有意思吗。
      

  15.   

    任何时候都不要想当然,这是程序员的大忌。
    <?php
    print_r($_GET);$data =  array( 
            array("red", "org", "yel", "green"), 
            array("red", "org", "yel", "green"), 
            array("red", "org", "yel", "green"), 
            array("red", "org", "yel", "green") 
    ); $p = http_build_query($data);
    ?>
    <a href='?<?php echo $p; ?>'>xxx</a>
    Array
    (
        [0] => Array
            (
                [0] => red
                [1] => org
                [2] => yel
                [3] => green
            )    [1] => Array
            (
                [0] => red
                [1] => org
                [2] => yel
                [3] => green
            )    [2] => Array
            (
                [0] => red
                [1] => org
                [2] => yel
                [3] => green
            )    [3] => Array
            (
                [0] => red
                [1] => org
                [2] => yel
                [3] => green
            ))你自己看看与原始数组有什么差异
      

  16.   

    遍历数组的方法有很多$data = array(
    array('a','b'),
    array('c','d'));foreach($data as $data1) {
    foreach($data1 as $data2){
    echo $data2;
    }
    }echo '<br/>';for($i = 0, $count1 = count($data); $i < $count1; ++$i) {
    for($j = 0, $count2 = count($data[$i]); $j < $count2; ++$j) {
    echo $data[$i][$j];
    }
    }echo '<br/>';reset($data);
    do {
    $data1 = current($data);
    do {
    echo current($data1);
    } while(next($data1));
    } while(next($data));echo '<br/>';$arrayobject = new ArrayObject($data);
    for($iterator = $arrayobject->getIterator();
        $iterator->valid();
        $iterator->next()) {
    $arrayobject1 = new ArrayObject($iterator->current());
    for($iterator1 = $arrayobject1->getIterator();
    $iterator1->valid();
    $iterator1->next()) {
    echo $iterator1->current();
    }
    }
      

  17.   

    超过50个字符都不建议用get传递。如果在一台服务器上,用内存 或 文件 传递,异机用post或者xml,soap