Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder stevenmw's Avatar
    Join Date
    Jun 2007
    Location
    OK
    Posts
    497
    Thanks
    27
    Thanked 31 Times in 31 Posts

    Very Basic Function Question.

    How can I write a function, and then use an if statement to do something if the function returns true?

    I basically want to write a function that consists of at if else statement. I want the if to return false and the else to return true. Then I want to write an if else statement that says something like..

    If the function returns true then do this, else do this.

    Am I making any sense?

  • #2
    New Coder
    Join Date
    Jan 2011
    Posts
    42
    Thanks
    5
    Thanked 0 Times in 0 Posts
    PHP Code:
    function your_function($var)
    {
    if(
    $var 'something'){
    $x true;
    } else {
    $x false;
    }
    return 
    $x;
    }

    $result your_function($var); 
    Then $variable will hold either true or false. Not sure if you need to pass a variable to the function but obviously change this as you need.

    And then if you wanted to do something with the result.
    PHP Code:
    if($result true) {

    } else {




  •  

    Posting Permissions

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