array_push - 对 Zend 测试示例感到困惑

array_push - befuddled with Zend test example

在学习 Zend 测试时,我 运行 浏览了这段有效的代码,但我无法弄清楚为什么在 array_push 中给出了两个 st运行ge 道具。 strtolower 和 ucfirst 用在应该有变量的地方。我是否遗漏了一些文档?

<?php
    $str = 'MY STRING';

    $funcs = array();

    array_push($funcs, 'strtolower', 'ucfirst');

    foreach ($funcs as $func) {
        $str = $func($str);
    }

    if ($str == 'My string') {
        echo "Correct";
    }
    else {
        echo "Incorrect";
    }
?>

PHP supports the concept of variable functions. This means that if a variable name has parentheses appended to it, PHP will look for a function with the same name as whatever the variable evaluates to, and will attempt to execute it. Among other things, this can be used to implement callbacks, function tables, and so forth.

来源:http://php.net/manual/en/functions.variable-functions.php

有趣的部分发生在这里:

$str = $func($str);

这是一个 variable function - 正在对字符串输入调用数组中列出的函数(通过 array_push)。