The eval () function calculates the string according to the PHP code.
Usage: eval (phpcode);
Case 1:
$a = ' name '; $b = ' my '; $d = ' $b $a is Helen '; Echo $d. " <br/> eval ("\ $d = \" $d \ ";"); echo $d. " <br/> ";
Output Result:
$b $a is helenmy name is Helen
Case 2:
Application scenario: Determine if the data passed by Ajax is an array format
$var config_value = $ (' #config_value '). Val ();//This is a configuration item that is similar to the array (all-in-one) arrays format $.ajax ({type: "POST", url : "ajax/checkarray.php", Data: "Config_value=" +config_value, Async:false, Success:functio N (data) {alert (data); } });
checkarray.php page
$config _value = $_post[config_value ']; $str 1 = $nns _config_item_value;eval ("\ $str 1 = $str 1;"); if (!is_array ($str 1)) {echo ' Config item value failed validation, not array or array format is incorrect! ";}
The eval () function of PHP