index函数的使用方法及实例

2025-10-27 13:13:25

1、先建好WAMP环境。

本案例中用的是phpnow,你也可以用别的。

简单安装完成目录大概长下图这样

index函数的使用方法及实例

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

把文件放到WEB目录下

index函数的使用方法及实例

3、myindex.php内容为

<?php   

//这是一个php index函数

function index(){

echo '这是一个php index函数';

}

index();//调用index函数

index函数的使用方法及实例

4、在浏览器地址栏输入http://localhost/myindex.php访问文件

index函数被调用后打印出 '这是一个php index函数';

index函数的使用方法及实例

5、前面是最简单的例子

你也可以把index函数写在类里面,然后new一个实例去调用index函数

<?php   

class abc{

//这是一个php index函数

function index(){

echo '这是一个abc类中的  index函数';

}

}

$aa = new abc();

$aa->index();

index函数的使用方法及实例

6、在浏览器地址栏输入http://localhost/myindex.php访问文件

index函数被调用后打印出 '这是一个abc类中的 index函数';

index函数的使用方法及实例

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