DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: [PHP] Confused with functions  (Read 5,445 times)

RedPillow

  • Pillows.
  • Member
  • Joined in 2008
  • **
  • Posts: 141
[PHP] Confused with functions
« on: February 05, 2011, 11:18 PM »
This has nothing to do with the thread I made few minutes ago.

Anyways ... I need help with these thing related to PHP-functions:

- How do I set what the function needs to work?

Like ...

Code: (php)
function countNumbers() {
echo ($x + $y);
}

Now, how do I declare, that the function I made needs parameters $x and $y to count like so:
countNumber(1, 2);


Second question is, can function return multiple values, like with a loop?

Code: (php)
function countNumbers() {
$rtnval = $x + $y;

for ($i = 0; $i <= 5; $i++) {
return $rtnval;
}
}


Third is, can I use function directly to output something like so:

Code: (php)
echo countNumbers();

or

Code: (php)
$numbers = countNumbers();
echo Numbers;

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: [PHP] Confused with functions
« Reply #1 on: February 06, 2011, 11:33 AM »
RedPillow, although you can get answers to your questions -- i think you would find that getting a book (free ebook or normal book) on php would be extremely helpful to you -- in very important ways.  I urge you to find one, it will be worth the effort to read it.

RedPillow

  • Pillows.
  • Member
  • Joined in 2008
  • **
  • Posts: 141
Re: [PHP] Confused with functions
« Reply #2 on: February 06, 2011, 11:41 AM »
Yeah ... there's sometimes just too much questions I need answer for.
I'll go check the nearest library!

Renegade

  • Tell me something you don't know...
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,291
    • Participated in NANY Challenge Three Times
    • Furry Fandom Badge - Furry Fandom
    • Linux User
Re: [PHP] Confused with functions
« Reply #3 on: February 06, 2011, 03:09 PM »
Check here:

http://php.net/manual/en/functions.arguments.php

function fName($variable)

etc. etc.
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

Original address: https://www.donationcoder.com/forum/index.php?topic=25533.0