PHP 中的 eval() 函式


eval() 函式將字串作為 PHP 程式碼進行評估。

語法

eval(code)

引數

  • code − 要評估的 PHP 程式碼。

返回值

eval() 函式返回 null,除非在程式碼字串中呼叫了 return 語句。然後返回傳遞給 return 的值。如果程式碼字串中有解析錯誤,eval() 將返回 false。

示例

 即時演示

<?php
   $one = "Demo";
   $two = "text";
   $res = 'This is $one $two!';
   echo $res. "<br>";
   eval("\$res = \"$res\";");
   echo $res;
?>

輸出

輸出如下。

This is $one $two!
This is Demo text!

更新於: 27-6月-2020

955 次瀏覽

啟動你的 職業

完成課程以獲得認證

開始
廣告
© . All rights reserved.