Re: function()
| From: | Justin French | Date: | Wed, 06 Nov 2002 00:47:15 +0000 |
| Subject: | Re: function() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-122886@lists.php.net to get a copy of this message | ||
Hi, this is the common way to do things:
<?
// declare function
function test($param)
{
$param = $param + 4;
return $param;
}
// option 1 -- prints 48
$param = test(44);
echo $param;
// option 2 -- prints 59
echo test(55);
?>
I *think* you can also make param part of the global array, but this is
totally UNTESTED code -- infact, I've never had the need to use the global
array in this way.
<?
// declare function
function test($param)
{
$_GLOBAL['param'] = $param + 4;
}
// option 1
echo $_GLOBAL['param'];
// option 2
echo $param;
?>
Good luck.
Justin
on 06/11/02 1:56 AM, Francisco Vaucher (fvaucher@tycoint.com) wrote:
> Hi to all,
>
> I have a problem with function() and some variables.
>
> The issue is this
>
> I declare the function, suppose:
>
> function test_func($param1) {
> echo $param1;
> }
>
> when I call the function like;
>
> <?php test_func(123)?>
>
> works OK!
>
> But if I try something like this:
>
> <?php
>
> test_func(123);
> echo $param;
>
> ?>
>
> This doesn't work. I need to get some variables values out of the function.
> Is there a way to make te variables defined in the function 'global' ? So I
> can use them after the function call.
>
> Thanks in advance!!
>
> regards,
>
> f.
>