The Differences Between return and echo

echo

Code

// Create function
function multiply($a, $b)
{
	$result = $a * $b;
	echo $result;
}

$result = multiply(3, 4); // output: 12
echo "<br>";
echo 'Result: ' . $result; // output: Result:

Output

12
Result:

return

Code

// Create function
function multiply0($a, $b)
{
	$result = $a * $b;
	return $result;
}

// Call the function
$result = multiply0(3, 4);
echo $result; // Output: 12
echo "<br>";

// Call the function
$a = 4;
$b = 5;
echo 'The result of ' . $a . ' x ' . $b . ' is: ' . multiply0 ($a, $b); // The result of 4 x 5 is: 20

Output

12
The result of 4 x 5 is: 20
NULL