Jump to content

Recommended Posts

Hey guys.

Can anyone tell me what this means?

function foo 
{
}

 

It is basic php but I don't get it. Should it be called for execution, or does it work automatically, or both?

The php manual at w3schools and php.net are too tough for me. That's why I posted here.

 

Thanks!

 

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.