Posted by J.O. Aho on 03/27/07 10:55
The87Boy wrote:
> I have defined some strings and functions in my script, but is there
> anyway I can access the strings in the function without defining them
> as:
> $n = 'Hey';
> function g($n='') {
> echo $n;
> }
> g($n)
>
This what you was thinking about?
--- example 1 ---
$n='Hello1';
function g() {
$global $n;
echo $n;
}
g();
--- eof ---
--- example 2 ---
$n='Hello2';
function g() {
echo $GLOBALS['n'];
}
g();
--- eof ---
Both are IMHO not a good way to do, better to send a variable into the
function (you can use references too)
--- example 3 ---
$n='Hello';
function g(&$nn) {
$nn.='3';
}
g($n);
echo $n;
--- eof ---
--
//Aho
Navigation:
[Reply to this message]
|