3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = ['p' => ['id' => TRUE]]; $b = ['p' => FALSE]; print "Behaves as expected.\n"; var_dump(array_merge_recursive($a, $b)); print "\n\nOMG internal array pointer shenanigans can affect the results of array_merge_recursive()!\n"; $a['p'][0] = 'SOMETHING, anything!'; unset($a['p'][0]); var_dump(array_merge_recursive($a, $b)); print "\n\nThis keeps happening…\n"; var_dump(array_merge_recursive($a, $b)); print "\n\n… not even resetting the internal array pointer helps …\n"; reset($a['p']); var_dump(array_merge_recursive($a, $b)); print "\n\n… nor casting to object, cloning, then back to array …\n"; $a['p'] = (array) clone (object) $a['p']; var_dump(array_merge_recursive($a, $b)); print "\n\n… only forcefully recreating a copy-by-value of the array by using array_slice().\n"; $a['p'] = array_slice($a['p'], 0); var_dump(array_merge_recursive($a, $b));
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
Behaves as expected. array(1) { ["p"]=> array(2) { ["id"]=> bool(true) [0]=> bool(false) } } OMG internal array pointer shenanigans can affect the results of array_merge_recursive()! array(1) { ["p"]=> array(2) { ["id"]=> bool(true) [1]=> bool(false) } } This keeps happening… array(1) { ["p"]=> array(2) { ["id"]=> bool(true) [1]=> bool(false) } } … not even resetting the internal array pointer helps … array(1) { ["p"]=> array(2) { ["id"]=> bool(true) [1]=> bool(false) } } … nor casting to object, cloning, then back to array … array(1) { ["p"]=> array(2) { ["id"]=> bool(true) [1]=> bool(false) } } … only forcefully recreating a copy-by-value of the array by using array_slice(). array(1) { ["p"]=> array(2) { ["id"]=> bool(true) [0]=> bool(false) } }
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
160.85 ms | 408 KiB | 5 Q