eval() function in PHP



The eval() function evaluates a string as PHP code.

Syntax

eval(code)

Parameters

  • code − The PHP code to be evaluated.

Return

The eval() function returns null unless a return statement is called in the code string. Then the value passed to return is returned. if there is a parse error in the code string, eval() returns false.

Example

 Live Demo

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

Output

The following is the output.

This is $one $two! This is Demo text!
Updated on: 2020-06-27T08:56:41+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements