On Thu, Jul 25, 2002 at 10:26:03PM +0200, Bas Jobsen wrote:
Hello,
I have this example code:
function doprint($a){foreach($a as $value)echo $value;}
doprint(array('1','test','hello','and'));
Question, is the array in memory after the function call?
So, should it be better to use this:
function doprint($a){foreach($a as $value)echo $value;}
doprint($temp=array('1','test','hello','and'));
unset($temp);
Depends on the scope you're talking about. The first way doesn't set the
array into memory outside the function, but it goes into memory inside the
function as $a. The second way puts it into memory twice, first as $temp
and second as $a.
Now, I'm not certain of what happens to your memory allocation inside the
function. I don't believe PHP automatically cleans up memory under such
circumstances. If I'm correct and you want to keep memory down, you could
do an unset() INSIDE the function.
--Dan
--
PHP classes that make web design easier
SQL Solution | Layout Solution | Form Solution
sqlsolution.info | layoutsolution.info | formsolution.info
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php