The function in PHP
Topics

Hi!
I'm Karsten and I want to help people learn German.
Buy me a coffee if you feel I did well.

The function in PHP

function php
There's a button below (sneak peek) to peek at the code.

Before we continue looking at data-types in computing we first have to understand an important concept: the function.

While writing code, you will find that you can reuse code to solve a problem that you have already coded a solution for. Say you want to echo something to a html document, and you have to do the same thing more than once, like saying hello:

Hello, nice to meet you.

If we want to say hello repeatedly we will do it this way, using a function:

Now I'm going to say hello to a few friends:

Hello, may the force be with you.

Hello, may the force be with you.

Hello, may the force be with you.

Hello, may the force be with you.

Now what if I don't want to only say "hello"? We can pass on a variable to a function like this:

I love pancakes.

Hi there!

No, not pancakes, again!

Can't we have strawberries?

It is very important to understand that you can't access the variable $anything from outside the function.

This is the content of $anything outside the function: "" (nothing).


>> continue
submit to reddit





Sneak peek of the server side code