PHP Scripting

Nested Function

learn PHP with the example of user define nested function for calculation

5/26/2020
0 views
nested-function.phpPHP
<?php
	function total($price, $tax, $discount) {
		
		/* Nested function */
		function inDollar($total, $conversion = 63.00) {
			return $total / $conversion;
		}
		$total = ($price + $tax) - $discount;
		echo "Total Price in Rs: ".round($total,2);
		
		/* Call Nested Function */
		echo "<br />Total Price in Dollar: ".round(inDollar($total),2);
	}
	
	total(155.52, 5.62, 10);
	
	/* Call nested function outside the function */
	echo "<br />Price in Dollar: ".round(inDollar(155.52), 2);
?>




/* Output */
Total Price in Rs: 151.14
Total Price in Dollar: 2.4
Price in Dollar: 2.47
PHPuser define functionnested function

Related Examples