Nested Function

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

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!