你是怎么传的?
<?php
print_r($_POST);
?>
<form action="" method="post">
<input type="checkbox" name="name_and_price[foodname][]" value='aa'/>1
<input type="checkbox" name="name_and_price[foodname][]" value='bb'/>2
<input type="checkbox" name="name_and_price[foodprice][]" value='1'/>3
<input type="checkbox" name="name_and_price[foodprice][]" value='3'/>4
<input type="submit" value="提交"/>
</form>
提交后显示
Array
(
    [name_and_price] => Array
        (
            [foodname] => Array
                (
                    [0] => aa
                    [1] => bb
                )            [foodprice] => Array
                (
                    [0] => 1
                    [1] => 3
                )        ))

解决方案 »

  1.   

    我的第一个文件是这样的:
    <form name="form1" method="post" action="totalcost.php">中间定义了一个二维数组:
    $name_and_price["foodname"][] = 'aa';
    $name_and_price["foodname"][] = 'bb';
    $name_and_price["foodname"][] = 'cc';
    $name_and_price["foodprice"][] = 1;
    $name_and_price["foodprice"][] = 3;
    $name_and_price["foodprice"][] = 5;
    $name_and_price["foodprice"][] = 7;
    </form>我在这个页面用echo $name_and_price["foodprice"][1] ;可正常输出值
    但在totalcost.php页面(即按了按钮后转到的页面)中的语句:
    echo $_POST[$food_and_price["foodname"][1]]; 却不能显示值?怎么回事?
      

  2.   

    不是很明白呢?能不能说详细一点我的第一个页面代码是这样的:
    <form name="form1" method="post" action="totalcost.php"><?
    $db_connect = mysql_connect("localhost","root","");
    mysql_select_db("fireshop", $db_connect);
    $char_sql = "SELECT * FROM foodtable";
    $p_sql = mysql_query($char_sql);  
        echo "<table border = 1>"; 
        echo "<tr>"."<th>"."菜名"."</th>"."<th>"."单价"."</th>"."<th>"."份数"."</th>"."<th>"."菜名"."</th>"."<th>"."单价"."</th>"."<th>"."份数"."</th>"."<th>"."菜名"."</th>"."<th>"."单价"."</th>"."<th>"."份数"."</th>"."</tr>"."<br>";
      $index = 0;
      $foodnumber = 0;   
      while($row = mysql_fetch_array($p_sql, MYSQL_NUM))
         {      if(($index)%3==0)
              echo "<tr>";
          echo "<th>";
          echo $row[0];
          echo "</th>";
          echo "<th>";
          echo $row[1];
          echo "</th>";
          $food_and_price[] = $row[0]; 
          $food_and_price[] = $row[1];//你是说这个数组应该放在哪里?
          echo "<th>";
          echo "<input type = text size = 3 name = textfield$foodnumber>";//textfield$foodnumber也是必须传的
          echo "</th>";
          $index++;
          $foodnumber++;
          if(($index%3)==0)
              echo "</tr>";
        } 
         echo "</table>";
    mysql_close($db_connect);
    ?>
      

  3.   

    用hidden input。<input type="hidden" name="food[]" value="$row[0]">
    <input type="hidden" name="price[]" value="$row[1]">
      

  4.   

    看了一下,个人觉得是楼主的概念问题....汗,这么说不要砍我. ice_berg16(寻梦的稻草人)老大已经说的很明确了,----你这样子怎么传? 要放到表单里才能传过去的,----也就是说,使用POST方法是一定要跟表单结合起来,才能够进行所谓的"传数据"的.楼主的代码里没有表单,第二个页面自然无法收到第一个页单的数据.而,第一个页面的确赋值了一个二维数组,所以在该页面使用echo能够显示数据.因为不明白楼主这么做的目的是什么,所以只能建议楼主不要使用POST方法,可以考虑使用SESSION,这个可以放二维数组.不知道这么讲,楼主能不能明白