At 13:46 22.02.2003, Patrick Teague said:
--------------------[snip]--------------------
>here's what I had that didn't print anything other than 3 blank lines for
>this section of code -
>
>$byteSize[0] = "bytes";
>$byteSize[1] = "kb";
>$byteSize[2] = "mb";
>
>function getMaxSize( $maxSize )
>{
> echo $byteSize[0] . "<br/>\n";
> echo $byteSize[1] . "<br/>\n";
> echo $byteSize[2] . "<br/>\n";
> ....
>}
--------------------[snip]-------------------- 

if you declare $bytesize global within the function it will work:

function getMaxSize( $maxSize )
{
 global $bytesize;
 echo $byteSize[0] . "<br/>\n";
}

You'd be still better off passing the array as variable:

function getMaxSize( $bytesize, $maxSize )
{
 echo $byteSize[0] . "<br/>\n";
}

And lastly, for performance issues, pass it as a reference:

function getMaxSize( &$bytesize, $maxSize )
{
 echo $byteSize[0] . "<br/>\n";
}

Without a reference, the array is copied to the function. By passing a
reference the function is working on the original array, no copy overhead.
Note: When passed as reference, any modification on the array within the
function will effect the original array (same is true if declared global).
Without reference the original array remains unchanged.


-- 
   >O     Ernest E. Vogelsinger
   (\)    ICQ #13394035
    ^     http://www.vogelsinger.at/



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

Reply via email to