0

I have a tiny while loop on my page, but it's also writing every iteration of the loop on my page, and I want those iterations (marked on the screenshot) to be not shown, here is the code:

while ($i < ($blocksize / 2) - 1) {?>
    <span class="nowrap"><?= $a.','.$b;?></span>
    <?= $a++; $b--; $i++;?>
    <span class="nowrap"><?= $b.','.$a;?></span>
    <?= $a++; $b--; $i++;?>
<?php };?>

And the output screenshot: Output

enter image description here

Please help me to solve this problem, Thanks everyone!

5
  • 3
    "Please help me to solve this problem" - What problem? You've just shown us some code and what output it gives you. You need to explain what result you're expecting or we won't have a clue. You also need to let us know what all those unknown variables contains. Commented Oct 30, 2018 at 6:11
  • I need to get rid of that iterations, which I have marked on the output screenshot, thanks. Commented Oct 30, 2018 at 6:14
  • 1
    Remove the echoes<?= $a++; $b--; $i++;?> to <?php $a++; $b--; $i++;?>. <?= is the same as <?php echo . Commented Oct 30, 2018 at 6:16
  • Working, thank you, can you post this as answer please? Commented Oct 30, 2018 at 6:18
  • I've posted an answer with an explanation. Commented Oct 30, 2018 at 6:22

2 Answers 2

2

The problem is that you're using <?= for the values you don't want to output. <?= is short hand for <?php echo.

If you just want to execute a statement but not output anything, just use <?php.

So change

<?= $a++; $b--; $i++;?>

to

<?php $a++; $b--; $i++;?>
Sign up to request clarification or add additional context in comments.

Comments

0

Try this

while ($i < ($blocksize / 2) - 1) {?>
    <span class="nowrap"><?= $a.','.$b;?></span>
    <?php $a++; $b--; $i++;?> // remove = here
    <span class="nowrap"><?= $b.','.$a;?></span>
    <?php $a++; $b--; $i++;?> //remove = here
<?php };?>

1 Comment

I would recommend to always use <?php instead of short tags <?, since they have been disabled by default since a bunch of years back.

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.