SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    user defined functions

    Can anybody explain how user defined functions works?

    example:
    PHP Code:
    function foo ($arg_1$arg_2, ..., $arg_n //what are these values and how they are defined?)
    {
        echo 
    "Example function.\n";
        return 
    $retval//what is returned here?

    my mobile portal
    ghiris.ro

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    User defined functions work just like the all other php functions.

    $arg_1, $arg_2, ..., $arg_n are function arguments, the values that you pass to the function to work with. Ex.:
    PHP Code:
    function sum($a$b){
      return 
    $a+$b;
    }

    echo 
    sum(2,3); //outputs 5 
    In the example, you see that the function is defined with two arguments which it use to add and return the result. This explains "return" as well.

    Hope this helps.
    Saul


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •