当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP get_defined_functions()用法及代码示例


get_defined_functions()function 是一个内置函数PHP它以数组格式返回所有定义的函数。

用法:

array get_defined_functions( bool $exclude_disabled = true )

Parameters: 该函数接受一个参数,如下所述:

  • $exclude_disabled: 它将检查禁用的函数是否将从返回值中排除,即该函数是否为错误的,它返回一个值,否则它将返回函数的完整定义。

返回值:返回值将是一个多维数组,其中包含所有已定义函数(即内置函数和用户定义函数)的列表。该函数返回函数的定义,或者如果参数是则返回函数的值真的.

示例 1:在此示例中,我们演示了get_defined_functions()函数。

PHP


<?php 
    function hello_world(){ 
        echo "GeeksforGeeks"; 
    } 
    $arr = get_defined_functions(); 
        
    print_r($arr); 
?>

输出:

Array
(
   [internal] => Array
       (
           [0] => zend_version
           [1] => func_num_args
           [2] => func_get_arg
           [3] => func_get_args
           [4] => strlen
           [5] => strcmp
           [6] => strncmp
           [7] => strcasecmp
           [8] => strncasecmp
           [9] => error_reporting
           [10] => define
           [11] => defined
}     [user] => Array
       (
           [0] => hello_world
       ) )
 

示例 2:在此示例中,我们将仅以数组形式打印用户定义的函数。

PHP


<?php 
    function hello_world(){ 
        echo "GeeksforGeeks"; 
    } 
    function bye_gfg(){ 
        echo "Bye GeeksforGeeks" ; 
    } 
    $arr = get_defined_functions(); 
        
    print_r($arr["user"]); 
?>

输出:

Array
(
   [0] => hello_world
   [1] => bye_gfg
)

参考: https://www.php.net/manual/en/function.get-defined-functions.php



相关用法


注:本文由纯净天空筛选整理自neeraj3304大神的英文原创作品 PHP get_defined_functions() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。