|
Posted by mosesdinakaran@gmail.com on 10/18/06 07:32
Hi everybody,
Today I faced a problem where I am very confused and I could not
solve it and I am posting here....
My question is
Is is possible to return a value to a particular function
The question may be silly or even meaning less but
please............
Below I have give a detailed description on why this question
appears to me.
Consider the following Code.
function one()
{
$ret_val = three();
echo "<br>RetVal:=".$ret_val;
}
function two($a,$b)
{
echo "<br>I am In function ".__FUNCTION__."()";
if($a==$b)
return true;
else
return false;
}
function three()
{
$array_one= array(1,2,3,4,5);
$array_two= array(1,2,3,4,5);
$a = array_rand($array_one,1);
$b = array_rand($array_two,1);
if(two($a,$b))
{
$ret_val = "$a and $b are equal";
echo "<br><br>I am In function ".__FUNCTION__."() and the
Val is $ret_val<br>";
return $ret_val;
}
else
{
three();
}
}
one();
Whats happpening here is.
1) I have three functions named one() two() and three();
2) From the first function one() I am calling function three()
3) In function three I have two arrays named $array_one and
$array_two
4) Then I am getting a random value from this two arrays as $a,$b
5) Then the function two is called to check weathe this two
random value is equal or not if the values are equal it returns true
else false
6) Function three is called recursly till the random value $a
and $b are equal. If it is equal I need to return the two values to
function one()
7) At one time $a and $b will be equal at this moment I return a
variable $ret_val from function three() to function one()
8) So In function one I can get the $ret_val
But I could not get the value $ret_val in function one()
I dont know why........
To my surprise at some rare condition I can get the value in
function one() all the othe times the return value is empty I could not
find this rare condition also.
I have spend a lot of time to find what is happening but in
vain..........
What I need is..
I should return the value $ret_val from function three() to
function one() But it is not happening I dont know weather the value
has been returned to function three() or to function two()
Can any body please help..............
regards
moses
[Back to original message]
|