我有一個形式,其中可以輸入幾行相同的幾次,這樣,添加在陣列甚至價值的關鍵是空的PHP
<input type="text" name="company[]"><input type="text" name="type[]">
<input type="text" name="company[]"><input type="text" name="type[]">
<input type="text" name="company[]"><input type="text" name="type[]">
現在我要輸入這些字段數據庫,所以我通過輸入字段循環,它工作正常。
但我有一個問題:有時循環中的字段可能爲空。即該公司將有一個價值,但不是類型。所以,我怎麼可以讓這樣的循環應該在這樣一個關鍵的輸出空值:
Array(
company => array(
[0] => string0
[1] => string1
[2] => string2
)
type => array(
[0] =>
[1] => string1
[2] => string2
)
)
所以你可以看到類型,首先關鍵是空的,所以我怎麼能做到這一點,
我想這樣做,但沒有結果,
$postFields = array('company', 'type');
$postArray = array();
foreach($postFields as $postVal){
if($postVal == ''){
$postArray[$postVal] = '';
}
else {
$postArray[$postVal] = $_POST[$postVal];
}
}
得到任何幫助,
是否爲每個標籤添加一個'value =「」'而不是爲您做? –
不,因爲我必須禁用空字段 – itsme
它是'type =「text」',在'$ _POST'數組中有一個空值_will_ ...我努力在這裏看到問題/期望的輸出... – Wrikken