Tue May 26 2020

Nested Function

PHP Scripting1781 views

File Name: nested-function.php

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

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