我有兩個數組,我將數組發佈到一個輸入中;在一個輸入框中發佈兩個數組並將其分開後,php
<input name='sistem[]' type='hidden' value='$items[$count]|$staff[$z]' />
// $count and $z are index
之後,我該如何將它們再次提取到兩個單獨的數組?
我有兩個數組,我將數組發佈到一個輸入中;在一個輸入框中發佈兩個數組並將其分開後,php
<input name='sistem[]' type='hidden' value='$items[$count]|$staff[$z]' />
// $count and $z are index
之後,我該如何將它們再次提取到兩個單獨的數組?
喜歡這個?
$items=new Array();
$staff=new Array();
foreach($_POST['sistem'] as $item){
$itemSplit=explode('|',$item);
$items[]=$itemSplit[0];
$staff[]=$itemSplit[1];
}
我不知道它的最好的解決辦法,但一個解決方案可能是您的前綴值
兩件事情:如果它實際上只是一個隱藏的輸入字段,你爲什麼不讓它進入兩個領域你的代碼?或者,甚至更好的是,將其存儲在會話中,以便在向Web服務器提交請求時,惡意用戶無法更改字段上的值?
但是,爲了回答直接的問題:
$parts = explode('|', $_REQUEST['sistem'][0]);
foreach ($_POST['sistem'] as $key => $value)
{
$tmp = explode("|", $value);
$items[$key] = $tmp[0];
$staff[$key] = $tmp[1];
}