How can PHP eval() function be used to execute stored PHP code?

The PHP eval() function can be used to execute stored PHP code by passing a string containing the PHP code to the eval() function. However, it is important to be cautious when using eval() as it can pose security risks if the input is not properly sanitized. It is recommended to validate and sanitize the input before passing it to eval() to prevent code injection attacks.

$stored_code = "echo 'Hello, World!';";
eval($stored_code);