Re: passing return value from fucntion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



No...I think it is not a proper way to program.If you have programming
experiences with  any other language, you'll understand this
naturally.
The original purpose of making a function is tell it some arguments,
and you get a result. It should have the fewest relationship with the
environment which, just like "a global variable" for instance, outside
of it.
So, we should understand the relation between caller and callee(I make
this word) as your main program as your function.

...
 echo calc($rs)."<br>";//at this point,the function will work,and give a result.
 ...
 
//a function named "calc":
 
 function calc($rightsid){
 ...
 if(...){
 } elseif ($rightsid == $oik6) {
  $res = ok;
  return $res;
 } elseif ($rightsid == $oik7) {
  $res = notok;
  return $res;
 }
 ...
 }



On Fri, 18 Mar 2005 10:43:30 +0200, William Stokes <kalles@xxxxxxxxxxxxx> wrote:
> Never mind I got it figured out. Had to set a global variable to make it
> visible.
> Thanks anyway
> 
> -Will
> 
> "Forest Liu" <oxware@xxxxxxxxx> kirjoitti
> viestissÃ:2f640a570503180005238eaa45@xxxxxxxxxxxxxxxxx
> I donot understand your problem clearly yet.
> I think there must be a caller and a callee (called function) when we
> talking about "passing arguments". That is to say, you write in your
> main program:
> 
> ...
> echo calc($rs)."<br>";
> ...
> 
> and make sure there is a function named "calc":
> 
> function calc($rightsid){
> ...
> if(...){
> } elseif ($rightsid == $oik6) {
>  $res = ok;
>  return $res;
> } elseif ($rightsid == $oik7) {
>  $res = notok;
>  return $res;
> }
> ...
> }
> 
> then the result calculated in the function would be passed to the
> point you calling in your main program.
> 
> Certainly,"ok" and "notok", I think they should be boolean, as "true"
> and "false". If you really write your code like that exactly, the two
> words "ok" and "notok" wont have any effective meaning.
> 
> wish it helps to you.
> 
> On Fri, 18 Mar 2005 09:33:13 +0200, William Stokes <kalles@xxxxxxxxxxxxx>
> wrote:
> > Hello,
> > Just simple question (I think?)
> >
> > How to pass return value from function to the main program?
> >
> > Here's example:
> > do some code in funtion to set the $res value:
> >
> > } elseif ($rightsid == $oik6) {
> >   $res = ok;
> >   return $res;
> > } elseif ($rightsid == $oik7) {
> >   $res = notok;
> >   return $res;
> > }
> >
> > How can I get to use the  $res in the main program. The return $res;
> > doesn't
> > pass the variable to the main program right?
> >
> > Thanks
> > -Will
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 
> --
>           Sincerely,
>                     Forest Liu(???)
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


-- 
         Sincerely,
                   Forest Liu(åäè)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux