如何呼叫儲存在變數中的字串中的函式 PHP?
要從儲存在變數中的字串中呼叫函式,請使用 $func。
語法如下
$func=’anyFunctionName’;
示例
PHP 程式碼如下
<!DOCTYPE html>
<html>
<body>
<?php
function hello(){
echo "Calling hello method."."<br>";
}
function welcome(){
echo "Calling welcome method."."<br>";
}
$func = 'hello';
$func();
?>
</body>
</html>輸出
將會產生以下輸出
Calling hello method.
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP