Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> PHP

Cách gọi hàm từ chuỗi lưu trong biến trong PHP

Để gọi hàm từ chuỗi lưu trong biến, dùng $func.

Cú pháp:

$func = 'anyFunctionName';

Ví dụ

<!DOCTYPE html> <html> <body> <?php 
function hello() {
    echo "Calling hello method.
"; } function welcome() { echo "Calling welcome method.
"; } $func = 'hello'; $func(); ?> </body> </html>

Kết quả

Calling hello method.