Just as Kevin Stone said, you can either use one of these constructions:
function func1() {
global $myarray;
array_push($myarray,1);
}
# _or_
function func2() {
array_push($GLOBALS['myarray'],1);
}
In fact, there is no performance decrease, because PHP will internally use the
same mechanism to access the array - as it would if you were not in a
function.
Another way would be to pass the array as a reference:
function func3(&$myarray) {
array_push($myarray, 1);
}
but this might decrease performace (in compare to the other ways, you will not
really notice it).
Sascha
Am Mittwoch, 18. September 2002 23:54 schrieb Anup:
> I want to use arrays (that are outside of a function) to be visible to a
> function. I understand that I must you global. But I was wondering is it
> possible to make it visible to only certain functions, similar to the
> 'friend' keyword in C (or C++ ?) ? The reason, is that I don't feel
> comfortable having globals, (I was brought up that way). Also, if you
> actually declare something global are there any disadvantages such as
> performance hits?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php