亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從輸入中的數組 php 獲取值并在塊中重復輸入

從輸入中的數組 php 獲取值并在塊中重復輸入

PHP
弒天下 2022-10-14 14:25:58
我有幾個輸入,我從數據庫中的數組中獲取值。我需要將所有輸入作為一個塊重復,而不是重復 html 我試圖只編寫一次 html,但是不知道如何使用 foreach 獲取值。所以我有這樣的輸入:<input type="text" name="x[]" value="<?php echo $p;?>"><input type="text" name2="y[]" value="<?php echo $refarray;?>">etc.我需要填寫這樣的值:foreach ($x as $p){foreach ($y as $r){ ?>我想重復該塊 3 次,所以我在一個 while 循環中運行它 3 次:<?php$i = 0;$times_to_run = 3;while ($i++ < $times_to_run){ ?>    <input type="text" name="x[]" value="<?php echo $p;?>">    <input type="text" name2="y[]" value="<?php echo $r;?>"><?php}?>這就是我希望打印輸出的方式:Block 1<input type="text" name="x[]" value="<?php echo $p[0];?>"><input type="text" name2="y[]" value="<?php echo $r[0];?>">Block 2<input type="text" name="x[]" value="<?php echo $p[1];?>"><input type="text" name2="y[]" value="<?php echo $r[1];?>">Block 3<input type="text" name="x[]" value="<?php echo $p[2];?>"><input type="text" name2="y[]" value="<?php echo $r[2];?>">如果不寫 html 3 次,我怎么能做到這一點?
查看完整描述

1 回答

?
揚帆大魚

TA貢獻1799條經驗 獲得超9個贊

假設您有數組$x,$r鍵為 0,1,2,3....等。


使用 foreach 將很容易和干凈地與 html 綁定


foreach ($x as $key => $p){ 

   echo  '<input type="text" name="x[]" value="<?php echo $p;?>">';

   echo  '<input type="text" name="y[]" value="<?php echo $r[$key];?>">';


}


查看完整回答
反對 回復 2022-10-14
  • 1 回答
  • 0 關注
  • 115 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號