[英]how to set the value of array into a input field with php
我有一個數組
$texts = [ "maybank2u.com",
"Open BillPayment",
"Status: Successful",
"Reference number 2950211545",
"Transaction date: 01 Feb 2016 13:09:17",
"Amount: RM100.00",
"From Account 564155051577 WCAa" ]
的HTML
<div class="row">
<div class="col-12">
<ul>
<?php foreach ($texts as $row =>$value): ?>
<li><h3> <?php echo ucfirst($value) ?></h3></li>
<?php endforeach ?>
</ul>
<label>Status:</label><input type="text" name="status" value="" id="status"><br>
</div>
</div>
我嘗試了此解決方案,但在我的情況下不起作用。 我想在輸入字段中設置$value
<div class="row">
<div class="col-12">
<ul>
<?php foreach ($texts as $row =>$value): ?>
<li><h3> <?php echo ucfirst($value) ?></h3></li>
<?php endforeach ?>
</ul>
<label>Status:</label><input type="text" name="status" value="<?php echo $texts[2] ?>" id="status"><br>
</div>
</div>
嘗試這個 -
<div class="row">
<div class="col-12">
<ul>
<?php foreach ($texts as $row =>$value): ?>
<li><h3> <?php echo ucfirst($value) ?></h3></li>
<?php endforeach ?>
</ul>
<label>Status:</label>
<input type="text" name="status" value="<?php echo ucfirst($texts[2]) ?>" id="status"><br>
</div>
您應該為數組使用索引:
<?php
$texts = [
//...
"status": "Successful",
"reference_number": "2950211545",
"transaction_date": "01 Feb 2016 13:09:17",
"amount": "RM100.00",
"from_account": "564155051577 WCAa"
]
?>
然后:
<input type="text" name="status" value="<?php echo $texts['status'] ?>" id="status">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.