Skip to content

Instantly share code, notes, and snippets.

@zualex
Created March 26, 2021 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zualex/a9f536006c1a24f7c4d4888077dc9fc0 to your computer and use it in GitHub Desktop.
Save zualex/a9f536006c1a24f7c4d4888077dc9fc0 to your computer and use it in GitHub Desktop.
array_merge without loop
<?php
function printMemory($start, $header) {
printf(
"%s - Time: %s | Memory (current): %s KB | Memory (max): %s KB" . PHP_EOL,
$header,
number_format(round((microtime(true) - $start) * 1000, 6), 6, ',', ''),
number_format(round((memory_get_usage() / 1024), 2), 2, ',', ''),
number_format(round((memory_get_peak_usage() / 1024), 2), 2, ',', '')
);
}
$big1 = range(0, 100000);
$big2 = array_fill(100000, 100000, 'string');
$big3 = range(200000, 100000);
$start = microtime(true);
$result = array_merge($big1, $big2, $big3);
printMemory($start, 'array_merge without loop');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment