3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function reduceMultidimensionalArraysToOneDimension(array $messages, $preffix) { $result = array(); foreach ($messages as $field => $msg) { if (is_array($msg)) { $result = array_merge($result, reduceMultidimensionalArraysToOneDimension($msg, $preffix . $field . '_')); } else { $result[$preffix . $field] = $msg; } } return $result; } $messages = array( 'second1' => array( 'm1' => 'lorem ipusum', 'third1' => array( 'm1' => 'lorem ipusum', 'm2' => 'lorem ipusum', ), 'm2' => 'lorem ipusum', 'm3' => 'lorem ipusum', 'third2' => array( 'm1' => 'lorem ipusum', 'm2' => 'lorem ipusum', ), 'm4' => 'lorem ipusum', ), 'm1' => 'lorem ipusum', 'second2' => array( 'm1' => 'lorem ipusum', 'third1' => array( 'm1' => 'lorem ipusum', 'm2' => 'lorem ipusum', ), 'm2' => 'lorem ipusum', 'm3' => 'lorem ipusum', 'third2' => array( 'm1' => 'lorem ipusum', 'm2' => 'lorem ipusum', ), 'm4' => 'lorem ipusum', ), 'm2' => 'lorem ipusum', ); echo "Starting array_merge\n"; $time = microtime(true); $result = reduceMultidimensionalArraysToOneDimension($messages, 'preffix_'); $time = microtime(true) - $time; echo 'array_merge() took ' . $time . " seconds\n";
Output for 7.0.6, 7.1.0
Starting array_merge array_merge() took 1.5020370483398E-5 seconds
Output for 7.0.4, 7.0.14
Starting array_merge array_merge() took 1.5974044799805E-5 seconds
Output for 7.0.5
Starting array_merge array_merge() took 9.0599060058594E-6 seconds
Output for 7.0.3
Starting array_merge array_merge() took 1.3113021850586E-5 seconds
Output for 7.0.2
Starting array_merge array_merge() took 1.6927719116211E-5 seconds
Output for 7.0.1
Starting array_merge array_merge() took 9.7751617431641E-6 seconds
Output for 7.0.0
Starting array_merge array_merge() took 1.1205673217773E-5 seconds
Output for 5.2.6, 5.6.28
Starting array_merge array_merge() took 3.9815902709961E-5 seconds
Output for 5.3.12 - 5.3.13, 5.3.15, 5.3.23, 5.3.29, 5.4.2, 5.4.13, 5.4.15 - 5.4.16, 5.6.21
Starting array_merge array_merge() took 3.504753112793E-5 seconds
Output for 5.3.10, 5.6.20
Starting array_merge array_merge() took 4.3869018554688E-5 seconds
Output for 5.6.19
Starting array_merge array_merge() took 3.3140182495117E-5 seconds
Output for 5.6.18
Starting array_merge array_merge() took 3.0040740966797E-5 seconds
Output for 5.5.27, 5.5.34, 5.6.17
Starting array_merge array_merge() took 2.5033950805664E-5 seconds
Output for 5.2.8, 5.2.10, 5.3.2, 5.5.31, 5.6.8, 5.6.13, 5.6.16
Starting array_merge array_merge() took 3.7908554077148E-5 seconds
Output for 5.6.15
Starting array_merge array_merge() took 5.3882598876953E-5 seconds
Output for 5.6.11, 5.6.14
Starting array_merge array_merge() took 3.1948089599609E-5 seconds
Output for 5.6.12
Starting array_merge array_merge() took 4.9114227294922E-5 seconds
Output for 5.6.10
Starting array_merge array_merge() took 2.9087066650391E-5 seconds
Output for 5.6.9
Starting array_merge array_merge() took 3.0994415283203E-5 seconds
Output for 5.2.2, 5.2.11, 5.3.1, 5.3.6 - 5.3.7, 5.4.8, 5.5.35
Starting array_merge array_merge() took 3.6954879760742E-5 seconds
Output for 5.5.33
Starting array_merge array_merge() took 2.8848648071289E-5 seconds
Output for 5.5.32
Starting array_merge array_merge() took 4.3153762817383E-5 seconds
Output for 5.2.17, 5.4.20, 5.5.28, 5.5.30
Starting array_merge array_merge() took 4.1007995605469E-5 seconds
Output for 5.3.0, 5.4.29, 5.5.29
Starting array_merge array_merge() took 4.1961669921875E-5 seconds
Output for 5.2.3, 5.2.5, 5.5.26
Starting array_merge array_merge() took 4.0054321289062E-5 seconds
Output for 5.2.16, 5.4.5, 5.4.37, 5.4.41, 5.5.25
Starting array_merge array_merge() took 5.1021575927734E-5 seconds
Output for 5.3.3, 5.5.24
Starting array_merge array_merge() took 3.4809112548828E-5 seconds
Output for 5.4.12, 5.4.35, 5.4.45
Starting array_merge array_merge() took 5.5074691772461E-5 seconds
Output for 5.4.44
Starting array_merge array_merge() took 0.00010395050048828 seconds
Output for 5.4.31 - 5.4.32, 5.4.43
Starting array_merge array_merge() took 5.0067901611328E-5 seconds
Output for 5.4.42
Starting array_merge array_merge() took 9.4890594482422E-5 seconds
Output for 5.4.40
Starting array_merge array_merge() took 8.2969665527344E-5 seconds
Output for 5.4.39
Starting array_merge array_merge() took 8.5830688476562E-5 seconds
Output for 5.4.38
Starting array_merge array_merge() took 0.00020599365234375 seconds
Output for 5.2.15, 5.3.21, 5.4.22, 5.4.34, 5.4.36
Starting array_merge array_merge() took 5.2928924560547E-5 seconds
Output for 5.3.9, 5.3.11, 5.4.24 - 5.4.25, 5.4.27, 5.4.30
Starting array_merge array_merge() took 3.4093856811523E-5 seconds
Output for 5.4.28
Starting array_merge array_merge() took 8.5115432739258E-5 seconds
Output for 5.4.26
Starting array_merge array_merge() took 3.3855438232422E-5 seconds
Output for 5.4.23
Starting array_merge array_merge() took 9.1075897216797E-5 seconds
Output for 5.4.21
Starting array_merge array_merge() took 8.2015991210938E-5 seconds
Output for 5.3.24, 5.4.19
Starting array_merge array_merge() took 9.2983245849609E-5 seconds
Output for 5.4.18
Starting array_merge array_merge() took 0.00010299682617188 seconds
Output for 5.3.5, 5.3.17, 5.4.3, 5.4.6, 5.4.10, 5.4.17
Starting array_merge array_merge() took 3.6001205444336E-5 seconds
Output for 5.3.18, 5.4.14
Starting array_merge array_merge() took 4.6968460083008E-5 seconds
Output for 5.2.9, 5.4.11
Starting array_merge array_merge() took 3.814697265625E-5 seconds
Output for 5.4.9
Starting array_merge array_merge() took 4.6014785766602E-5 seconds
Output for 5.3.19, 5.4.7
Starting array_merge array_merge() took 9.8943710327148E-5 seconds
Output for 5.3.8, 5.4.4
Starting array_merge array_merge() took 5.1975250244141E-5 seconds
Output for 5.4.1
Starting array_merge array_merge() took 5.6982040405273E-5 seconds
Output for 5.4.0
Starting array_merge array_merge() took 0.00010514259338379 seconds
Output for 5.3.28
Starting array_merge array_merge() took 9.5129013061523E-5 seconds
Output for 5.3.27
Starting array_merge array_merge() took 9.7990036010742E-5 seconds
Output for 5.2.14, 5.3.16, 5.3.26
Starting array_merge array_merge() took 9.3936920166016E-5 seconds
Output for 5.3.25
Starting array_merge array_merge() took 9.7036361694336E-5 seconds
Output for 5.3.22
Starting array_merge array_merge() took 0.0001068115234375 seconds
Output for 5.3.4, 5.3.20
Starting array_merge array_merge() took 3.7193298339844E-5 seconds
Output for 5.2.13, 5.3.14
Starting array_merge array_merge() took 4.5061111450195E-5 seconds
Output for 5.2.12
Starting array_merge array_merge() took 3.9100646972656E-5 seconds
Output for 5.2.7
Starting array_merge array_merge() took 5.3167343139648E-5 seconds
Output for 5.2.4
Starting array_merge array_merge() took 0.00010919570922852 seconds
Output for 5.2.1
Starting array_merge array_merge() took 3.3855438232422E-05 seconds
Output for 5.2.0
Starting array_merge array_merge() took 5.6028366088867E-05 seconds
Output for 5.1.3, 5.1.6
Starting array_merge array_merge() took 4.2915344238281E-05 seconds
Output for 5.1.5
Starting array_merge array_merge() took 5.1975250244141E-05 seconds
Output for 5.1.1, 5.1.4
Starting array_merge array_merge() took 4.5061111450195E-05 seconds
Output for 5.1.2
Starting array_merge array_merge() took 7.1048736572266E-05 seconds
Output for 5.1.0
Starting array_merge array_merge() took 4.3153762817383E-05 seconds
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/Sd4bu on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_ARRAY, expecting ')' in /in/Sd4bu on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_ARRAY, expecting ')' in /in/Sd4bu on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/Sd4bu on line 3
Process exited with code 255.