Home > database >  php <br> before var_dump not producing line break
php <br> before var_dump not producing line break

Time:11-23

I have written php script as follows but the line break used before var_dump function is not producing a line break before giving bool(true). Please help me in find what mistake I am doing.

<?php
class Fruit {
}
$apple = new Fruit();
echo "<br>" . var_dump($apple instanceof Fruit) . "<br>";
?>

Output: bool(true)

No line break before bool(true)

CodePudding user response:

Instead of using <br> for the output and splitting it into 3 complete statements (as suggested in the comment), it is better to use <pre>.

class Fruit {
  public $prop = 1;
}
$apple = new Fruit();

echo "<pre>";
var_dump($apple instanceof Fruit,$apple);
echo "</pre>";

Output:

bool(true)
object(Fruit)#2 (1) {
  ["prop"]=>
  int(1)
}

With the line breaks which are contained in the var_dump output are processed.

CodePudding user response:

You could try

echo "<pre>"; echo var_dump($apple); echo "</pre>";

Technically @aynber and @CBroe are right.

  • Related