╰┈➤ The eval() function evaluates a string as PHP code. The string must be valid PHP code and must end with
semicolon.
// Example #1 eval() 
$string = 'cup';
$string2= 'coffee';
$str = 'This is a $string with $string2 in it.';
echo $str. "\n"; // outputs: This is a $string with $string2 in it.
eval("\$str = \"$str\";");
echo $str. "\n"; // outputs: This is a cup with coffee in it.
► Let's make another simple example for better understanding. Put a mathematical operation in a string. obviously PHP can't solve example in case of putting it in a string.◄
$operation =  "20 - 5"; 
echo $operation; // outputs 20 - 5
echo eval( $operation. ';' );  // it doesn't show anything.
echo eval( 'echo '. $operation. ';' ); // outputs 15
// or
eval( '$temp = ' .$operation. ';' );
echo $temp; // outputs 15
by Luka Khitaridze
2 years ago
PHP
Function
0
Pro tip: use ```triple backticks around text``` to write in code fences