DonationCoder.com Forum

Other Software => Developer's Corner => Topic started by: RedPillow on February 05, 2011, 05:18 PM

Title: [PHP] Confused with functions
Post by: RedPillow on February 05, 2011, 05: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 [Select]
  1. function countNumbers() {
  2. echo ($x + $y);
  3. }

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 [Select]
  1. function countNumbers() {
  2. $rtnval = $x + $y;
  3.  
  4. for ($i = 0; $i <= 5; $i++) {
  5. return $rtnval;
  6. }
  7. }


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

Code: PHP [Select]
  1. echo countNumbers();

or

Code: PHP [Select]
  1. $numbers = countNumbers();
  2. echo Numbers;
Title: Re: [PHP] Confused with functions
Post by: mouser on February 06, 2011, 05: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.
Title: Re: [PHP] Confused with functions
Post by: RedPillow on February 06, 2011, 05:41 AM
Yeah ... there's sometimes just too much questions I need answer for.
I'll go check the nearest library!
Title: Re: [PHP] Confused with functions
Post by: Renegade on February 06, 2011, 09:09 AM
Check here:

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

function fName($variable)

etc. etc.