0
我正在爲Zen Cart的模塊編寫一些代碼。 $ stores_id是含3個值的數組:for循環沒有迴應我的數組中的期望值
$stores_id[0]="1";
$stores_id[1]="2";
$stores_id[2]="3";
用下面的代碼我試圖回波隱藏的輸入字段,填充數據從陣列
for ($i=0, $n=sizeof($stores_id); $i<$n; $i++)
{
echo zen_draw_hidden_field('stores_id['. $stores_id[$i]['stores_id'] .']', htmlspecialchars(stripslashes($stores_id[$stores_id[$i]['stores_id']]), ENT_COMPAT, CHARSET, TRUE));
}
回送的結果是:
<input type="hidden" value="2" name="stores_id[1]">
<input type="hidden" value="3" name="stores_id[2]">
<input type="hidden" name="stores_id[3]">
,而我希望它是:
<input type="hidden" value="1" name="stores_id[1]">
<input type="hidden" value="2" name="stores_id[2]">
<input type="hidden" value="3" name="stores_id[3]">
誰能告訴我我做錯了什麼?
謝謝你,那確實起作用。我使用了第一個選項,因爲在正常的操作中,數組可以用任意值的組合填充,然後第二個選項不起作用。 – Zen4All
通過刪除'['stores_id']'來進一步簡化代碼。 現在回顯線爲: 'echo zen_draw_hidden_field('stores_id ['。$ stores_id [$ i]。']',htmlspecialchars(stripslashes($ stores_id [$ i]),ENT_COMPAT,CHARSET,TRUE));'' – Zen4All