Home > database >  wrong order echo in php
wrong order echo in php

Time:09-26

I want to echo the integers 1 and 2 in this order and with a break between them. I wrote this extremely simple code:

<?php
echo 1 . "<br>";
echo 2 . "<br>";
?>

Strangely, the output is: 2 1 I find it very weird, is there a problem with the way I put the breaks?

CodePudding user response:

What about using PHP_EOL instead?

```php
echo 1 . PHP_EOL;
echo 2 . PHP_EOL;
```

Otherwise, if you are echo'ing in a website, I find kinda weird it's not printing a new line between the numbers. Maybe the problem is not that code but the context surrounding that code. Consider sharing the context of that code to help you more if needed :)

CodePudding user response:

This should work as long as you're rendering HTML and not some other kind of output. Try creating example.php with this code:

<!DOCTYPE html>
<html>
  <head>
    <title>My PHP test</title>
  </head>
  <body>
  <?php
      echo 1 . '<br>';
      echo 2 . '<br>';
  ?>
  </body>
</html>
  • Related