O'Reilly logo

PHP for Teens by Maneesh Sethi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Designing Your Own Functions

You might be wondering why you would ever want to design a function. Functions allow your program to become a lot more robust and capable. Functions make your program modular, meaning that you can use parts of your program in other programs without worrying about problems. This means less work for you overall. Let’s take an example. Let’s say I had a program that added the numbers 1 through 10. This is how a sample program would look if I wrote it without functions:

<?php echo "The following counter will add up the numbers 1 through 10"; echo "<br>Please wait, your numbers are being tabulated below."; $runningcounter=0; for ($x=1; $x <= 10; $x++) { $runningcounter = $runningcounter + $x; } echo '<p>Your result is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required