Including Other Files
Unless you are restricting yourself to the simplest programming ventures, you will want to share code among your scripts at some point. The most basic need for this is to have a standard header and footer for your website, with only the body content changing. However, you might also find yourself with a small set of custom functions you use frequently, and it would be an incredibly bad move to simply copy and paste the functions into each of the scripts that use them.
The most common way to include other files is with the include keyword. Save this script as include1.php:
<?php for($i = 10; $i >= 0; $i -= 1) { include "echo_i.php"; }?>
Then save this script as echo_i.php:
<?php echo $i;?>
If you run include1.php, PHP ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access