Thauwa Posted December 17, 2010 Share Posted December 17, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/221962-php-functions/ Share on other sites More sharing options...
trq Posted December 17, 2010 Share Posted December 17, 2010 functions. Quote Link to comment https://forums.phpfreaks.com/topic/221962-php-functions/#findComment-1148563 Share on other sites More sharing options...
denno020 Posted December 17, 2010 Share Posted December 17, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/221962-php-functions/#findComment-1148621 Share on other sites More sharing options...
Thauwa Posted December 17, 2010 Author Share Posted December 17, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/221962-php-functions/#findComment-1148646 Share on other sites More sharing options...
denno020 Posted December 17, 2010 Share Posted December 17, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/221962-php-functions/#findComment-1148649 Share on other sites More sharing options...
Thauwa Posted December 17, 2010 Author Share Posted December 17, 2010 Oh WOW! You really clarified the matter for me. Trust me, you've explained it to me better that php.net and w3schools did. phew. Thanks denno and thorpe (for unlocking the topic)! Quote Link to comment https://forums.phpfreaks.com/topic/221962-php-functions/#findComment-1148652 Share on other sites More sharing options...
denno020 Posted December 17, 2010 Share Posted December 17, 2010 Ok cool. Wasn't sure if I was making it easy to understand or not, but I'm glad it was . Denno Quote Link to comment https://forums.phpfreaks.com/topic/221962-php-functions/#findComment-1148655 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.