index函数的使用方法及实例
1、先建好WAMP环境。
本案例中用的是phpnow,你也可以用别的。
简单安装完成目录大概长下图这样

2、函数是需要写在文里的,所以我们新建个文件,假设叫做myindex.php
把文件放到WEB目录下

3、myindex.php内容为
<?php
//这是一个php index函数
function index(){
echo '这是一个php index函数';
}
index();//调用index函数

4、在浏览器地址栏输入http://localhost/myindex.php访问文件
index函数被调用后打印出 '这是一个php index函数';

5、前面是最简单的例子
你也可以把index函数写在类里面,然后new一个实例去调用index函数
<?php
class abc{
//这是一个php index函数
function index(){
echo '这是一个abc类中的 index函数';
}
}
$aa = new abc();
$aa->index();

6、在浏览器地址栏输入http://localhost/myindex.php访问文件
index函数被调用后打印出 '这是一个abc类中的 index函数';

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:34
阅读量:79
阅读量:37
阅读量:93
阅读量:71