Function return values

To return a value from a function, the return keyword is used before the variable being returned.

 

<?php

	function myFunction($argOne, $argTwo) {

		$something = $argOne + $argTwo ;

		return $something ;
	}

	$myVar = 17 ;

	$yourVar = 42 ;

	$returnValue = myFunction($myVar, $yourVar) ;

	Echo "The sum of \$myVar $myVar and \$yourVar $yourVar is $returnValue" ;

?>

Displays:

The sum of $myVar 17 and $yourVar 42 is 59

Leave a Reply