Search code examples
phpvariablesecho

PHP best way to echo variables


I was watching a PHP tutorial and noticed that the teacher was adding varibles to his echo statements in a different way to me. This got me thinking, which way should I be using? Is one more correct than the other?

Here's what the teacher was doing

echo "Example " . $example;

Here's what I do

echo "Example $example";

My method works, but I don't want to get into any bad habits. Could someone please tell me which way I should be using (preferably with some evidence)?


Solution

  • According to the PHP.NET documentation, his way is proper.

    http://php.net/manual/en/language.operators.string.php

    echo "Example " . $example;