【问题标题】:form input into array将输入形成数组
【发布时间】:2012-10-09 20:57:58
【问题描述】:

我有一个工具,我必须输入一些单词,它必须输入:

$_POST['searchqueries']

我有多个输入形式,必须在 ['searchqueries'] 中返回,如下所示: 单词1,单词2,单词3,单词4。

这是我现在拥有的,但它只是返回数组,而不是分开

<fieldset style="border: none;">
<label for="searchquerie1">Zoekwoord 1:</label><input type="text" id="searchquerie1" name="searchqueries[]" maxlength="256" value="" /><br>
<label for="searchquerie2">Zoekwoord 2:</label><input type="text" id="searchquerie2" name="searchqueries[]" maxlength="256" value="" /><br>
<label for="searchquerie3">Zoekwoord 3:</label><input type="text" id="searchquerie3" name="searchqueries[]" maxlength="256" value="" /><br>
<label for="searchquerie4">Zoekwoord 4:</label><input type="text" id="searchquerie4" name="searchqueries[]" maxlength="256" value="" /><br>
<input type="hidden" name="fset"/>
</fieldset>

我必须做些什么来完成这项工作

问候

大卫

【问题讨论】:

  • 我不知道我是否真的得到了你的问题。但你可以将名称属性从“searchqueries[]”更改为“word1”、“word2”等,然后值将在 $_POST["word1"], $_POST["word2"].. 中传输

标签: php arrays forms input


【解决方案1】:

当然,如果您将值作为数组 searchqueries[] 传递,您将检索到一个数组……

【讨论】:

    【解决方案2】:

    使用foreach

    $varb = mysql_real_escape_string($_POST['searchqueries']);//sanitize the input
    foreach($varb as $vals)
    echo $vals['searchqueries'];
    

    【讨论】:

      【解决方案3】:
      $combined = implode(',', $_POST['searchqueries']);
      

      字符串 $combined with 包含用逗号分隔的所有值。

      【讨论】:

        【解决方案4】:

        您可以使用implode 将数组中的元素与, 粘合成一个字符串。

        $arr = array('a','b','c');

        $str = implode(',',$arr);
        echo $str; // will output a,b,c
        

        【讨论】:

          猜你喜欢
          • 2015-03-25
          • 2015-08-19
          • 1970-01-01
          • 1970-01-01
          • 2019-06-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-03-14
          相关资源
          最近更新 更多