Nested Function

PHP Programming

PHP Programming Examples

<?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

Learn more about user define function