Skip to content

Instantly share code, notes, and snippets.

@TheFrozenFire
Created December 11, 2013 01:39
Show Gist options
  • Save TheFrozenFire/7903749 to your computer and use it in GitHub Desktop.
Save TheFrozenFire/7903749 to your computer and use it in GitHub Desktop.
Array union experiment
<?php
$b = rand(0, 1);
$c = rand(0, 1);
for($i = 0; $i < 1000000; $i++) {
$a = ['foo' => 1];
if($b) {
$a['bar'] = 2;
}
if($c) {
$a['baz'] = 3;
}
}
<?php
$b = rand(0, 1);
$c = rand(0, 1);
for($i = 0; $i < 1000000; $i++) {
$a = ['foo' => 1]
+ ($b?['bar' => 2]:[])
+ ($c?['baz' => 3]:[]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment