0

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

<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

4
  • You have multiple values and only one <input>. Which $value do you want to insert there? The "Status: Successful" one? So you end up with value="successful"? Commented Sep 10, 2019 at 4:28
  • @ObsidianAge I Want to insert "Status: Successful" into the input field Commented Sep 10, 2019 at 4:30
  • <input type="text" name="status" value="<?php echo ($texts[2]) ?>" id="status"><br> is it a good solutions? Commented Sep 10, 2019 at 4:34
  • on what basis you want status: successful? Commented Sep 10, 2019 at 6:35

3 Answers 3

0

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>

Sign up to request clarification or add additional context in comments.

2 Comments

what if I only want to set "Status: Successful" into the input field?
<input type="text" name="status" value="<?php echo ($texts[2]) ?>" id="status"><br> is it a good solutions?
0
<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>

Comments

0

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">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.