---
title: "Nested Function"
description: "learn PHP with the example of user define nested function for calculation"
url: "https://www.geekboots.com/php/nested-function"
markdown_url: "https://www.geekboots.com/php/nested-function/md"
category: "PHP Scripting"
author: "Geekboots"
published: "2016-06-06"
updated: "2026-12-03T07:04:27.505Z"
tags: ["PHP", "user define function", "nested function"]
---

# Nested Function (PHP Scripting)

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

## Source Code

### nested-function.php

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

## Related Code Examples

- [Fetch MySQL Data](https://www.geekboots.com/php/fetch-mysql-data) ([Markdown](https://www.geekboots.com/php/fetch-mysql-data/md))
- [Imagick](https://www.geekboots.com/php/imagick) ([Markdown](https://www.geekboots.com/php/imagick/md))
- [Read XML File](https://www.geekboots.com/php/read-xml-file) ([Markdown](https://www.geekboots.com/php/read-xml-file/md))
- [Create XML File](https://www.geekboots.com/php/create-xml-file) ([Markdown](https://www.geekboots.com/php/create-xml-file/md))
- [Read CSV file](https://www.geekboots.com/php/read-csv) ([Markdown](https://www.geekboots.com/php/read-csv/md))
- [Read File](https://www.geekboots.com/php/read-file) ([Markdown](https://www.geekboots.com/php/read-file/md))
- [Copy File](https://www.geekboots.com/php/copy-file) ([Markdown](https://www.geekboots.com/php/copy-file/md))
- [Create Delete File](https://www.geekboots.com/php/create-delete-file) ([Markdown](https://www.geekboots.com/php/create-delete-file/md))

---
Source: [Geekboots](https://www.geekboots.com/php/nested-function)
