Modular Websites

Variables

No one likes to do anything twice, and programing languages are full of ways to optimize the code. Just as CSS centralizes the instructions for how the web page looks, and PHP modularizes the HTML web site into a number of components, programing languages create variables and give them names to optimize the code. This is how to write the last statement using a variable:

<!DOCTYPE html>
<?php
$myString = "Hello!";
echo $myString;
echo "I'm a PHP script!";
?>

The dollar sign $ signifies that myString is a variable, and the equal sign = assigns it to the text "Hello". When this variable is echoed, it writes out "Hello". The savings in this example are not exactly spectacular, but you get the idea. It saves programers from having to write and update the same code over and over again.