---
title: "PHP函数的嵌套调用"
author: "cakin24"
date: "2016-12-29T20:24:34Z"
tags: []
categories: ["编程语言"]
slug: "php"
draft: false
lastmod: "2016-12-29T20:24:34Z"
id: 2348108
url: "https://cakin24.iteye.com/blog/2348108"
---

**一 PHP代码**

01. `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"`
02. `"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">`
03. `<htmlxmlns="http://www.w3.org/1999/xhtml">`
04. `<head>`
05. `<metahttp-equiv="Content-Type"content="text/html; charset=gb2312"/>`
06. `<title>实现货币转换</title>`
07. `</head>`
08. `<body>`
09. `<?php`
10. `function example($price,$tax)`
11. `{`
12. `function examples($yuan,$taxs=7.5)`
13. `{`
14. `return $yuan*$taxs;`
15. `}`
16. `$total=$price+($price*$tax);`
17. `echo "价格是:$total 美元<br>";`
18. `echo "价格是:".examples($total)."元<br>";`
19. `}`
20. `example(15.00,0.75);`
21. `?>`
22. `</body>`
23. `</html>`

**二 运行结果**

价格是:26.25 美元  
价格是:196.875元

**三 运行说明**

1、所谓嵌套函数，就是在函数中定义并调用其他函数。

2、嵌套函数可以将一个复杂的功能分解成多个子函数，再通过调用的方式结合起来，有利于提高函数的可读性。