You are here: Re: Transfer variabele outside function « PHP Language « IT news, forums, messages
Re: Transfer variabele outside function

Posted by James Pittman on 11/05/01 11:13

Marco J.L. wrote:

> Hello,
>
> how can I transfer a variable from a function to the part after the
> function?
>
> thnx,
>
> Marco J.L.
>
>
> <?php
>
> $var="before function";
> func_xxxxx();
> echo $var;
>
> Function func_xxxxx() {
> $var = "after function";
> }
> ?>
>
>
>

I believe you can do this if you pass the variable by reference:

$var = "before function";
myFunc($var);
echo $var;

function myFunc(\$foo) {
$foo = str_replace("before", "after", $foo);
}


But a more elegant way is to return the variable back to the program:

$var = "before function";
$var = myFunc($var);
echo $var;

function myFunc($foo) {
// Do some manipulation on $foo and set it to $bar
$bar = str_replace("before", "after", $foo);
return $bar;
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация