Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 09, 2016, 01:23:18 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: [PHP] Confused with functions  (Read 1649 times)

RedPillow

  • Member
  • Joined in 2008
  • **
  • Posts: 141
  • Pillows.
    • View Profile
    • Read more about this member.
    • Donate to Member
[PHP] Confused with functions
« on: February 05, 2011, 05:18:24 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;

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,429
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: [PHP] Confused with functions
« Reply #1 on: February 06, 2011, 05:33:32 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

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

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,220
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: [PHP] Confused with functions
« Reply #3 on: February 06, 2011, 09:09:14 AM »
Check here:

http://php.net/manua...ctions.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