函数_exists()是PHP中的内置函数。如果我们想检查PHP脚本中是否存在函数(),函数_exists()非常有用。它用于检查内置函数和用户定义函数。
null
语法 :
boolean function_exists($function_name)
参数 :此函数接受单个参数 $function_name .这是我们要在已定义函数列表中搜索的函数的名称。这是一个字符串类型的参数。
返回值 :此函数返回布尔值。如果存在名为$function_name的函数,则返回TRUE,否则返回FALSE。对于“include_once”、“echo”等构造,此函数也将返回FALSE。
下面的程序演示了PHP中的函数_exists()函数:
项目1:
<?php // PHP program to illustrate function_exists() // checking if the in_array() built-in function // exists or not if (function_exists( 'in_array' )) { echo "in_array() function is available." ; } else { echo "in_array() function is not available." ; } ?> |
输出:
in_array() function is available.
方案2 :
<?php // PHP program to illustrate function_exists() // declaring a function named WelcomeMsg function WelcomeMsg() { echo "Welcome to GeeksforGeeks" ; } // checking if the function named WelcomeMsg // exists or not if (function_exists( 'WelcomeMsg' )) { echo "WelcomeMsg() function is available." ; } else { echo "WelcomeMsg() function is not available." ; } ?> |
输出:
WelcomeMsg() function is available.
参考 : http://php.net/manual/en/function.function-exists.php
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END