function updateArray ( $array )
{
foreach ( $array as $index => $tmp ) {
$array[ $index ]++;
}
return $array;
}
echo memory_get_usage( true ) . ' / ' . memory_get_peak_usage( true ); # 0.25 Mb / 0.25 Mb
$array = [ ];
for ( $i = 0; $i < 1048576; $i++ ) {
$array[] = 0;
}
echo memory_get_usage( true ) . ' / ' . memory_get_peak_usage( true ); # 84.5 Mb / 84.5 Mb
$array = updateArray( $array );
echo memory_get_usage( true ) . ' / ' . memory_get_peak_usage( true ); # 85.25 Mb / 221 Mb
function updateArray ( &$array )
{
foreach ( $array as $index => $tmp ) {
$array[ $index ]++;
}
}
echo memory_get_usage( true ) . ' / ' . memory_get_peak_usage( true ); # 0.25 Mb / 0.25 Mb
$array = [ ];
for ( $i = 0; $i < 1048576; $i++ ) {
$array[] = 0;
}
echo memory_get_usage( true ) . ' / ' . memory_get_peak_usage( true ); # 84.5 Mb / 84.5 Mb
updateArray( $array );
echo memory_get_usage( true ) . ' / ' . memory_get_peak_usage( true ); # 84.5 Mb / 84.5 Mb