Skip to content
PHP Logo

What are the differences between using include and execute functions in PHP for accessing external code?

When including external code in PHP, the main differences between using include and execute functions are that include simply inserts the specified file's content into the current file, while execute actually runs the external file as a separate PHP script. This means that any variables or functions defined in the included file will be accessible in the current script when using include, while execute will execute the external script independently.

php
// Using include to insert external code
include 'external_file.php';

// Using execute to run external code as a separate script
exec('php external_file.php');