Simple Arguments 
Simple Arguments
by Brad Hussey
Video Lecture 31 of 45
Not yet rated
Views: 766
Date Added: May 14, 2017

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

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.

Comments

There are no comments. Be the first to post one.
  Post comment as a guest user.
Click to login or register:
Your name:
Your email:
(will not appear)
Your comment:
(max. 1000 characters)
Are you human? (Sorry)