#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    58
    Rep Power
    15
    I want to turn this into a function:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $PROSPECT = "found"; // set by default
    $prospect_product == something from a form.
    [/code]
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    // begin crucial testing //
    if ($prospect_product == "hello")
    {
    $product = "A hello product";
    }
    else
    {
    $product = "a realy bad product";
    $PROSPECT = "not found"; // change your mind about $PROSPECT
    }
    // end crucial testing //
    [/code]
    As you can see the // crucial testing // uses only one variable, but is the testing inside it, it needs to change another variable.
    I know that if I make the crucial testing a function I can reach $PROSPECT by Global'ing it.
    But if I need to Global it back outside the function, how do I do then?
    How do I return two values from a function?
    Make them one variable? Make them an array?

    Grateful!


    ------------------

    peterbe.com
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Washington, USA
    Posts
    52
    Rep Power
    15
    You can return into an array

    function returnTwo($in) {
    if($in == 1) { $return[0] = "value1"; $return[1] = "value2"; }
    else { $return[0] = "value2"; $return[1] = "value1"; }
    return($return);
    }

    $array = returnTwo(1);
    // $array[0] = value1
    // $array[1] = value2



    ------------------
    <UL TYPE=SQUARE>
    <LI> TD Scripts
    <LI> Script School
    <LI>php-scripts
    </UL>
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Annapolis, Maryland US
    Posts
    113
    Rep Power
    15
    Pass by reference should work as well

    <?

    $condition="found";
    $incoming="not_hello";

    function testMe($incoming, &$condition)
    {
    if($incoming=="hello")
    {
    $product="a hello product";
    return $product;
    }

    else
    {
    $product="a really bad product";
    $condition="not found";
    return $product;
    }
    }

    $product=testMe($incoming, &$condition);

    print"The value of product is $product<BR>";
    print"The value of condition is $condition";

    ?>
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    58
    Rep Power
    15
    pass by reference worked.


    ------------------

    peterbe.com

Similar Threads

  1. Uploading Files
    By vivekjain in forum ASP Programming
    Replies: 0
    Last Post: February 16th, 2004, 11:21 PM
  2. help with an isGreater function
    By qiushiming in forum C Programming
    Replies: 18
    Last Post: February 5th, 2004, 08:23 AM
  3. Pulling out variables from a superglobal via function
    By voice220 in forum PHP Development
    Replies: 11
    Last Post: January 27th, 2004, 10:52 AM
  4. Replies: 0
    Last Post: January 22nd, 2004, 07:43 AM
  5. function returns berserk values for unknown reasons
    By c0ldshadow in forum C Programming
    Replies: 7
    Last Post: January 16th, 2004, 04:05 PM

IMN logo majestic logo threadwatch logo seochat tools logo