比如:<?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
<head>
</head>
<body>
<center>
就是这么个意思吧,我怎么把data 这个数组让 test.php 使用?
<a href = test.php?xxx= $data> ssss </a></center>
</body></html
0=red&1=org&2=yel&3=green再怎么做,你用该知道了
数组当函数的参数怎么用呀?<?php $data = array("red", "org", "yel", "green"); EchoTLPic($data); 可以直接这么用吗?
?>
<?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
function EchoTLPic($test)
{
print_r($test);
}
EchoTLPic($data);
$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长度是有限制的,所以数组不能太大。
完全没有必要去写什么 EchoTLPic、echoarray 等无聊的函数或做什么编码解码
function echoarray($data)
{
foreach($data as $k => $c)
{ echo "$k ==> $c <br/>"; }
}
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)
{
}
{
foreach($c as $e => $u)
{
echo "$e ==> $u <br/>";
}
//echo "$k ==> $c <br/>";
}
{
$data2 = $data1[i];
for($j =0, $num2 = count($data2); $j < $num2; $j++)
{
echo " ==> $data2[$j] <br/>";
}
}
如果这个数组是固定的,你可以将数组保存在单独的一个文件里,然后让所有需要用的程序include一下。
如果某一页需要用这个数组的第3个数据,前一页只需要把3传递过去就可以了。
GET方式下(一种是表单method是GET,一种就是在URL地址里传值),数据长度是有限制的,至少,比POST方式要少得多。
<?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
))你自己看看与原始数组有什么差异
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();
}
}