小编pot*_*mic的帖子

将函数名称作为参数传递给函数

我有这样的功能:

function test($str,$func) {
    $func($str);
    //Something more here
}
Run Code Online (Sandbox Code Playgroud)

我怎么能在那里传递一个函数名?我想做test("Hello",strtolower);或喜欢test("Bye",sometextprocessfunc);

php

5
推荐指数
2
解决办法
2695
查看次数

嵌套include_once问题

这是我的目录树:

  • /
    • 的index.php
  • 包括/
    • 的functions.php
    • head.php
    • connect.php
  • 子/
    • 的index.php

在我的head.php和connect.php都有:

include_once 'include/functions.php';
Run Code Online (Sandbox Code Playgroud)

我在根文件夹中的index.php包括以下两个:head.php和connect.php,如下所示:

include_once 'include/connect.php';
include_once 'include/head.php;'
Run Code Online (Sandbox Code Playgroud)

但是,当sub /中的index.php包含functions.php和head.php时,它们将无法包含functions.php.这是我在sub/index.php中包含的内容:

include_once '../include/connect.php';
include_once '../include/head.php';
Run Code Online (Sandbox Code Playgroud)

如果我将head.php和connect.php更改为:include_once'../include/functions.php';

sub/index.php通常会包含所有内容,但root中的index.php将无法加载functions.php.

我怎样才能解决这个问题?

PHP版本:5.2.*

php

1
推荐指数
1
解决办法
325
查看次数

标签 统计

php ×2