Results 1 to 3 of 3

Thread: function return value

  1. #1

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Resolved function return value

    Is it possible in php to return a value from a function?

    eg. In VB it would be written like the below which would return True or False.
    VB Code:
    1. Function MyFunction() as Boolean
    2. 'do whatever inside function
    3.  
    4. 'MyFunction = True
    5.  
    6. 'or
    7.  
    8. 'MyFunction = False
    Last edited by lintz; Sep 18th, 2005 at 11:34 PM.

  2. #2
    Lively Member {yak}'s Avatar
    Join Date
    Aug 2005
    Posts
    119

    Re: function return value

    Yep it is:
    PHP Code:
    <?php

    function myFunc()
    {
        
    $foo "yakbar";
        if(
    $foo == "foobar")
        {
            return 
    $foo;
        }
        else
        {
            return 
    false;
        }
    }

    echo 
    myFunc();

    ?>
    {yak}

  3. #3

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: function return value

    Thanks {yak}. I knew there must have been a way

    So would the below code work?

    PHP Code:
    if (MyFunction() == "True") {
    //Do this because the function returned True
    }
    else {
    //Do this because the function returned False


    EDIT: I played around with it and it does work.
    Last edited by lintz; Sep 18th, 2005 at 11:36 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width