内爆多个输入

时间:2012-11-02 06:03:41

标签: input implode

我有这样的输入:

<div id="fruit1">
    <input type="text" name="name[]" value="Apple" />
    <input type="text" name="qty[]" value="2" />
</div>
<div id="fruit2">
    <input type="text" name="name[]" value="Blackberry" />
    <input type="text" name="qty[]" value="4" />
</div>
<div id="fruit3">
    <input type="text" name="name[]" value="Banana" />
    <input type="text" name="qty[]" value="1" />
</div>

是否有一种简单的方法使用implode来获得这样的结果(单行):

Apple;2|Blackberry;4|Banana;1|

1 个答案:

答案 0 :(得分:0)

修改

试试这段代码:

$display = "";
$ctr = 0;
foreach ($_POST['name'] as $data) :
    $display .= $data.";".$_POST['qty'][$ctr]."|";
    $ctr++;
endforeach;

echo $display;