[英]how to set the value of array into a input field with php
I have an array 我有一个数组
$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 的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>
I tried this solution but it's not working in my case. 我尝试了此解决方案,但在我的情况下不起作用。 I want to set the value of
$value
into the input field 我想在输入字段中设置
$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>
Try This -- 尝试这个 -
<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>
You should use index for your array: 您应该为数组使用索引:
<?php
$texts = [
//...
"status": "Successful",
"reference_number": "2950211545",
"transaction_date": "01 Feb 2016 13:09:17",
"amount": "RM100.00",
"from_account": "564155051577 WCAa"
]
?>
Then: 然后:
<input type="text" name="status" value="<?php echo $texts['status'] ?>" id="status">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.