
Lecture Description
Lecture 31: Simple Arguments
Functions can be incredibly powerful, because you can program them to do almost anything you want them to. One important step in making your functions even smarter is to use "arguments" within your function. Not the type of argument where you and a friend are bickering about a disagreement, I'm talking about arguments within functions — two very different things.
Think of an argument like a variable. Your program can pass extra information to your functions using arguments. You specify your arguments within the parenthesis after your function name, and you can have as many as you want, as long as they're comma separated.
Let's look at an example of a function with a single argument:
function hangTen($location) {
echo "We're surfing in $location!";
}
hangTen("Hawaii");
hangTen("California");
hangTen("Newfoundland");
So, in the above example, we're passing an argument to the hangTen() function. Later in our script, we call our function several times with a string of text within each parenthesis, and each time we call our function with a new argument value, that value will display on the screen along with the text we provided in our function.
The output will look like this:
We're surfing in Hawaii!
We're surfing in California!
We're surfing in Newfoundland!
Let's look at an example with two arguments:
function multiplyTogether($val1, $val2) {
$product = $val1 * $val2;
echo "The product of the two numbers is: $product";
}
multiplyTogether(14, 27);
All we did here was add another argument, separated by comma, then when we called our multiplyTogether() function later in the script, we provided two values to take the place of our $val1 and $val2 arguments.
The result?
The product of the two numbers is: 378
DOWNLOAD COURSE FILES HERE
www.bradhussey.ca/download-php-course
Course Index
- Welcome to the Course
- What is PHP?
- What Does PHP Do?
- Tools to Get Started
- Download Course Files
- Your First PHP Page
- PHP Syntax
- PHP Variables
- More Variables
- Defining Constants
- Get Your Hands Dirty
- Arrays
- Associative Arrays
- Multi-Dimensional Arrays
- Get Your Hands Dirty
- If Statements
- Else
- Else If
- Get Your Hands Dirty
- Comparison Operators
- Logical Operators
- Arithmetic Operators
- String Operators
- Assignment Operators
- While Loop
- For Loop
- Foreach Loop
- Do While Loop
- PHP Functions
- Custom Functions
- Simple Arguments
- Final Website
- Basic Layout
- Global Header & Footer
- Copyright & Hours of Operation
- Team Member Array & Template
- Menu Array & Template
- Understanding $_GET
- Menu Item Template
- Contact Form
- Understanding $_POST
- Form Validation
- Form Submission
- Upload Your Website Live
- Wrap Up
Course Description
This course is a Total Beginner's Guide to Coding Your Very Own Dynamic Websites with PHP, so you need no prior knowledge or experience — although it's a good idea that you know some HTML (my beginner's guide "Build a Website from Scratch with HTML & CSS" will get teach you everything you need to know).
So — why learn PHP? Well, PHP is a very powerful scripting language used by millions of websites. Some of the most popular websites and frameworks utilize PHP to build their dynamic websites. PHP works very well with HTML, and therefore will allow you to start coding dynamic websites quickly without having to learn some of the more complicated scripting languages out there.