Skip to content

Instantly share code, notes, and snippets.

@yvan-sraka
Last active November 6, 2017 17:22
Show Gist options
  • Save yvan-sraka/0ff886762b197f614c6ddfcff1109e15 to your computer and use it in GitHub Desktop.
Save yvan-sraka/0ff886762b197f614c6ddfcff1109e15 to your computer and use it in GitHub Desktop.
Show difference between return and echo keyword in PHP
<?php
$name = "Bob";
echo $name;
// VS //
echo "Bob";
// ---------------------------- //
function what_is_my_name() {
return "Bob";
} // => STRING: "Bob"
echo what_is_my_name(); // display "Bob"
$result = what_is_my_name();
echo $result; // display "Bob"
// VS //
function what_is_my_name() {
echo "Bob";
} // => NULL
what_is_my_name(); // display "Bob"
$result = what_is_my_name();
echo $result; // display NULL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment