-1

I need to print some cards in html, but I'll receive a php array with the number of days I'll have to print. I've tried this, but isn't working.

<div>
<div class="row" style="padding: 0px 30px">
    <?php foreach ($array as $num):?>
        <div class="col">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title"><?php $num ?></h3>
                </div>
                <div class="card-body">
                    <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
                </div>
            </div>
        </div>
    <?php endforeach ?>
</div>

6
  • this is my arrays: <?php $array = array(1, 2, 3, 4, 5); $days = array("segunda","terça","quarta","quinta","sexta"); ?> Commented May 31, 2019 at 12:34
  • 1
    edit your question please. Do not post code in comments. Commented May 31, 2019 at 12:34
  • 3
    Replace <?php $num ?> with <?= $num ?>. Check the documentation Commented May 31, 2019 at 12:35
  • 2
    "it isn't working" is not a helpful problem statement. What is happening? In what way is that different from what you want/expect? What debugging have you already done? Commented May 31, 2019 at 12:36
  • Try <?php echo $days[0]; ?> Replace the number 0 with the specific index you want to echo/display. Commented May 31, 2019 at 13:07

1 Answer 1

0

Maybe one of these loops will help:

foreach ($array as $mykey=>$myval) {
    echo $myval;
}

foreach ($array as $mykey=>$myval) {
    echo $array[$mykey];
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.