【问题标题】:more then one Values in one Parameter from $_get一个参数中的多个值来自 $_get
【发布时间】:2017-06-24 11:01:17
【问题描述】:

我有一个 html 表单,其中一个参数提交多个值。 如何在 php 中处理它

整个过程是这样的:

单参数:
购物车 = 项目 1
购物车 = 项目 2
购物车 = 项目 3
购物车 = 项目 3
姓名 = 马克斯
姓氏 = 布朗
地址 = 纽约

【问题讨论】:

  • 请张贴 HTML 表单..
  • 您可以将shoppingcart[] 用于字段,您将获得值数组。

标签: php html forms input


【解决方案1】:

您必须为数组指定名称,例如

<input type="text" name="shoppingcart[]"/>

【讨论】:

    【解决方案2】:

    如果你提交了一个数组,你应该将它用作一个数组,例如:

    $my_item_array  = $_GET['shoppingcart '];
    
    
    foreach($my_item_array as $key => $value){
    
     echo $value . <br />;
    }
    

    【讨论】:

      【解决方案3】:

      使用参数作为html形式的数组类型shoppingcart[],你可以处理它的php循环。

      foreach($_GET['shoppingcart'] as $item){
              echo $item;
      }
      

      【讨论】:

        【解决方案4】:

        你可以这样使用,

        表格,

        item1: <input type="text" name="shoppingcart[]"/>
        item2: <input type="text" name="shoppingcart[]"/>

        然后在你的php代码中,

        $items = $_GET["shoppingcart"];
        

        【讨论】:

          【解决方案5】:

          $_GET 是 php 中的超级全局变量。它是一个数组,你可以按以下形式使用它:

          假设有以下 html 格式:

          <form action="welcome_get.php" method="get">
          Name: <input type="text" name="name"><br>
          E-mail: <input type="text" name="email"><br>
          <input type="submit">
          </form>
          

          welcome_get.php 看起来像这样:

          Welcome <?php echo $_GET["name"]; ?><br>
          Your email address is: <?php echo $_GET["email"]; ?>
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2020-01-10
            • 2016-05-02
            • 2016-12-05
            • 2014-11-05
            • 1970-01-01
            相关资源
            最近更新 更多