Jump to content

PHP Functions


Thauwa

Recommended Posts

It's normally written as

function foo(){

}

You use the parenthesis to pass variables into the function, so if you have a function to count something, you might pass a variable that represents the maximum count, so the function will be finished when this value is reached.

 

Functions need to be called, they won't just run.

 

That's a pretty basic explanation.

 

Denno

Link to comment
https://forums.phpfreaks.com/topic/221962-php-functions/#findComment-1148621
Share on other sites

Thanks.

But this confuses me. Pardon my impertinence.

Please tell me whether I am right.

 

 

<?php 
function €() 
{ 
   echo 'foo'; 
} 
?> 

 

After defining this function, when I type somewhere

a();

Is "foo" echoed? Or should I type

echo a();

?

 

 

In simple, are functions like variables that can store other commands instead of strings?

 

Thanks people. I really appreciate your help.

Link to comment
https://forums.phpfreaks.com/topic/221962-php-functions/#findComment-1148646
Share on other sites

I'm not sure the name of the symbol that you have used as the name of that function, but it appears that you've then called it a lol.

 

Anyways, yes, wherever you call

a();

 

foo will be echoed.

 

I guess, in a way, it's almost like an include.. Replacing

a();

with

echo 'foo';

whereever a() is written.

 

I wouldn't think of functions as variables though. Think of them as blocks of code that will acheive a similar goal (usually indicated by the name of the function).

So for example, your function should have been called

printFoo()

Whenever you call printFoo(), foo will be printed to the browser..

 

Making more sense?

 

Denno

Link to comment
https://forums.phpfreaks.com/topic/221962-php-functions/#findComment-1148649
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.