August 22nd, 2000, 05:07 AM
-
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 ¬
August 22nd, 2000, 09:58 AM
-
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>
August 22nd, 2000, 10:07 AM
-
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";
?>
August 22nd, 2000, 10:39 AM
-
pass by reference worked.
------------------
¬ peterbe.com ¬