當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。