3v4l.org

run code in 300+ PHP versions simultaneously
<?php function initArray() { $arr = []; for ($i = 0; $i < 20000; $i++) { $arr[] = ['name' => 'John', 'email' => 'john@me.com']; } return $arr; } function flatten1($array, $depth = INF) { $result = []; foreach ($array as $item) { $item = $item instanceof Collection ? $item->all() : $item; if (! is_array($item)) { $result[] = $item; } else { $values = $depth === 1 ? array_values($item) : flatten1($item, $depth - 1); foreach ($values as $value) { $result[] = $value; } } } return $result; } function flatten2($array, $depth = INF) { $result = []; foreach ($array as $item) { $item = $item instanceof Collection ? $item->all() : $item; if (! is_array($item)) { $result[] = $item; } else { $values = $depth === 1 ? array_values($item) : flatten2($item, $depth - 1); array_push($result, ...$values); } } return $result; } echo PHP_EOL."CONCAT".PHP_EOL; $arr = initArray(); $start = microtime(true); flatten1($arr); var_export(microtime(true) - $start); echo PHP_EOL."ARRAY_PUSH".PHP_EOL; $arr = initArray(); $start = microtime(true); flatten2($arr); var_export(microtime(true) - $start);
Output for 8.0.3
CONCAT 0.011332988739013672 ARRAY_PUSH 0.010454893112182617
Output for 8.0.2
CONCAT 0.009495973587036133 ARRAY_PUSH 0.007452964782714844
Output for 8.0.1
CONCAT 0.013718128204345703 ARRAY_PUSH 0.007508993148803711
Output for 8.0.0
CONCAT 0.014808893203735352 ARRAY_PUSH 0.0120849609375
Output for 7.4.16
CONCAT 0.014866113662719727 ARRAY_PUSH 0.012192010879516602
Output for 7.4.15
CONCAT 0.012033939361572266 ARRAY_PUSH 0.012140035629272461
Output for 7.4.14
CONCAT 0.008901119232177734 ARRAY_PUSH 0.007806062698364258
Output for 7.4.13
CONCAT 0.014340877532958984 ARRAY_PUSH 0.012954950332641602
Output for 7.4.12
CONCAT 0.009435892105102539 ARRAY_PUSH 0.007543087005615234
Output for 7.4.11
CONCAT 0.01160883903503418 ARRAY_PUSH 0.0074350833892822266
Output for 7.4.10
CONCAT 0.015121936798095703 ARRAY_PUSH 0.012266874313354492
Output for 7.4.9
CONCAT 0.03523683547973633 ARRAY_PUSH 0.011080026626586914
Output for 7.4.8
CONCAT 0.009899139404296875 ARRAY_PUSH 0.0073010921478271484
Output for 7.4.7
CONCAT 0.00931406021118164 ARRAY_PUSH 0.007606029510498047
Output for 7.4.6
CONCAT 0.010873079299926758 ARRAY_PUSH 0.01119089126586914
Output for 7.4.5
CONCAT 0.013588905334472656 ARRAY_PUSH 0.013835906982421875
Output for 7.4.4
CONCAT 0.009492158889770508 ARRAY_PUSH 0.007398128509521484
Output for 7.4.3
CONCAT 0.009927988052368164 ARRAY_PUSH 0.00769495964050293
Output for 7.4.2
CONCAT 0.013969898223876953 ARRAY_PUSH 0.0135650634765625
Output for 7.4.1
CONCAT 0.009604930877685547 ARRAY_PUSH 0.0075991153717041016
Output for 7.4.0
CONCAT 0.009368896484375 ARRAY_PUSH 0.0072269439697265625
Output for 7.3.28
CONCAT 0.010527849197387695 ARRAY_PUSH 0.008077859878540039
Output for 7.3.27
CONCAT 0.009797811508178711 ARRAY_PUSH 0.008496999740600586
Output for 7.3.26
CONCAT 0.015426158905029297 ARRAY_PUSH 0.012993097305297852
Output for 7.3.25
CONCAT 0.016397953033447266 ARRAY_PUSH 0.013484954833984375
Output for 7.3.24
CONCAT 0.010251998901367188 ARRAY_PUSH 0.00857400894165039
Output for 7.3.23
CONCAT 0.011165857315063477 ARRAY_PUSH 0.008143186569213867
Output for 7.3.22
CONCAT 0.0162811279296875 ARRAY_PUSH 0.012817144393920898
Output for 7.3.21
CONCAT 0.01610708236694336 ARRAY_PUSH 0.013572931289672852
Output for 7.3.20
CONCAT 0.009747982025146484 ARRAY_PUSH 0.007646083831787109
Output for 7.3.19
CONCAT 0.015223026275634766 ARRAY_PUSH 0.013350963592529297
Output for 7.3.18
CONCAT 0.012978076934814453 ARRAY_PUSH 0.01146697998046875
Output for 7.3.17
CONCAT 0.010483980178833008 ARRAY_PUSH 0.007583141326904297
Output for 7.3.16
CONCAT 0.010821104049682617 ARRAY_PUSH 0.008685111999511719
Output for 7.3.15
CONCAT 0.013276100158691406 ARRAY_PUSH 0.011153936386108398
Output for 7.3.14
CONCAT 0.01547098159790039 ARRAY_PUSH 0.013261079788208008
Output for 7.3.13
CONCAT 0.01852703094482422 ARRAY_PUSH 0.01652383804321289
Output for 7.3.12
CONCAT 0.016703128814697266 ARRAY_PUSH 0.009013891220092773
Output for 7.3.11
CONCAT 0.009367942810058594 ARRAY_PUSH 0.007587909698486328
Output for 7.3.10
CONCAT 0.010234832763671875 ARRAY_PUSH 0.008143901824951172
Output for 7.3.9
CONCAT 0.010499000549316406 ARRAY_PUSH 0.008020877838134766
Output for 7.3.8
CONCAT 0.009418010711669922 ARRAY_PUSH 0.008134126663208008
Output for 7.3.7
CONCAT 0.014249086380004883 ARRAY_PUSH 0.012300968170166016
Output for 7.3.6
CONCAT 0.011703014373779297 ARRAY_PUSH 0.008096933364868164
Output for 7.3.5
CONCAT 0.015094995498657227 ARRAY_PUSH 0.012733936309814453
Output for 7.3.4
CONCAT 0.009504079818725586 ARRAY_PUSH 0.007681846618652344
Output for 7.3.3
CONCAT 0.009665966033935547 ARRAY_PUSH 0.007534027099609375
Output for 7.3.2
CONCAT 0.011981964111328125 ARRAY_PUSH 0.00871896743774414
Output for 7.3.1
CONCAT 0.052661895751953125 ARRAY_PUSH 0.01362919807434082
Output for 7.3.0
CONCAT 0.016633987426757812 ARRAY_PUSH 0.009933948516845703
Output for 7.2.34
CONCAT 0.010920047760009766 ARRAY_PUSH 0.008161067962646484
Output for 7.2.33
CONCAT 0.011066913604736328 ARRAY_PUSH 0.008476018905639648
Output for 7.2.32
CONCAT 0.016891002655029297 ARRAY_PUSH 0.014093160629272461
Output for 7.2.31
CONCAT 0.011201858520507812 ARRAY_PUSH 0.008200883865356445
Output for 7.2.30
CONCAT 0.011018037796020508 ARRAY_PUSH 0.008095979690551758
Output for 7.2.29
CONCAT 0.011096000671386719 ARRAY_PUSH 0.008296966552734375
Output for 7.2.28
CONCAT 0.016676902770996094 ARRAY_PUSH 0.0102691650390625
Output for 7.2.27
CONCAT 0.011126041412353516 ARRAY_PUSH 0.007824897766113281
Output for 7.2.26
CONCAT 0.01138615608215332 ARRAY_PUSH 0.012295007705688477
Output for 7.2.25
CONCAT 0.011393070220947266 ARRAY_PUSH 0.008131980895996094
Output for 7.2.24
CONCAT 0.011332988739013672 ARRAY_PUSH 0.007912874221801758
Output for 7.2.23
CONCAT 0.011154890060424805 ARRAY_PUSH 0.02190709114074707
Output for 7.2.22
CONCAT 0.012212038040161133 ARRAY_PUSH 0.01338815689086914
Output for 7.2.21
CONCAT 0.01691889762878418 ARRAY_PUSH 0.01444387435913086
Output for 7.2.20
CONCAT 0.02138495445251465 ARRAY_PUSH 0.025621891021728516
Output for 7.2.19
CONCAT 0.011566162109375 ARRAY_PUSH 0.00899195671081543
Output for 7.2.18
CONCAT 0.013957977294921875 ARRAY_PUSH 0.013214826583862305
Output for 7.2.17
CONCAT 0.029202938079833984 ARRAY_PUSH 0.009434938430786133
Output for 7.2.16
CONCAT 0.011224985122680664 ARRAY_PUSH 0.009068012237548828
Output for 7.2.15
CONCAT 0.013414144515991211 ARRAY_PUSH 0.012075185775756836
Output for 7.2.14
CONCAT 0.012119054794311523 ARRAY_PUSH 0.008968830108642578
Output for 7.2.13
CONCAT 0.012697935104370117 ARRAY_PUSH 0.008986949920654297
Output for 7.2.12
CONCAT 0.015561819076538086 ARRAY_PUSH 0.012192964553833008
Output for 7.2.11
CONCAT 0.051557064056396484 ARRAY_PUSH 0.008646965026855469
Output for 7.2.10
CONCAT 0.01178121566772461 ARRAY_PUSH 0.01332402229309082
Output for 7.2.9
CONCAT 0.012269973754882812 ARRAY_PUSH 0.008260965347290039
Output for 7.2.8
CONCAT 0.018145084381103516 ARRAY_PUSH 0.01395106315612793
Output for 7.2.7
CONCAT 0.011322021484375 ARRAY_PUSH 0.00804901123046875
Output for 7.2.6
CONCAT 0.021418094635009766 ARRAY_PUSH 0.020914077758789062
Output for 7.2.5
CONCAT 0.011931896209716797 ARRAY_PUSH 0.008320093154907227
Output for 7.2.4
CONCAT 0.02581501007080078 ARRAY_PUSH 0.012740135192871094
Output for 7.2.3
CONCAT 0.012026786804199219 ARRAY_PUSH 0.008222103118896484
Output for 7.2.2
CONCAT 0.059118032455444336 ARRAY_PUSH 0.014834165573120117
Output for 7.2.1
CONCAT 0.012953996658325195 ARRAY_PUSH 0.008625030517578125
Output for 7.2.0
CONCAT 0.01568317413330078 ARRAY_PUSH 0.009599924087524414
Output for 7.1.33
CONCAT 0.013725996017456055 ARRAY_PUSH 0.011597156524658203
Output for 7.1.32
CONCAT 0.014722108840942383 ARRAY_PUSH 0.01088404655456543
Output for 7.1.31
CONCAT 0.018132925033569336 ARRAY_PUSH 0.01848316192626953
Output for 7.1.30
CONCAT 0.019368886947631836 ARRAY_PUSH 0.017264842987060547
Output for 7.1.29
CONCAT 0.02130889892578125 ARRAY_PUSH 0.009868860244750977
Output for 7.1.28
CONCAT 0.01807093620300293 ARRAY_PUSH 0.017149925231933594
Output for 7.1.27
CONCAT 0.012879133224487305 ARRAY_PUSH 0.01160120964050293
Output for 7.1.26
CONCAT 0.013138055801391602 ARRAY_PUSH 0.00995016098022461
Output for 7.1.25
CONCAT 0.012701988220214844 ARRAY_PUSH 0.011950969696044922
Output for 7.1.24
CONCAT 0.018445968627929688 ARRAY_PUSH 0.019017934799194336
Output for 7.1.23
CONCAT 0.012018918991088867 ARRAY_PUSH 0.010536909103393555
Output for 7.1.22
CONCAT 0.017978906631469727 ARRAY_PUSH 0.0165560245513916
Output for 7.1.21
CONCAT 0.01868414878845215 ARRAY_PUSH 0.017776012420654297
Output for 7.1.20
CONCAT 0.01949310302734375 ARRAY_PUSH 0.017058134078979492
Output for 7.1.19
CONCAT 0.017753124237060547 ARRAY_PUSH 0.0167999267578125
Output for 7.1.18
CONCAT 0.012950897216796875 ARRAY_PUSH 0.010939836502075195
Output for 7.1.17
CONCAT 0.0175478458404541 ARRAY_PUSH 0.016737937927246094
Output for 7.1.16
CONCAT 0.012032032012939453 ARRAY_PUSH 0.0116729736328125
Output for 7.1.15
CONCAT 0.011762857437133789 ARRAY_PUSH 0.011989116668701172
Output for 7.1.14
CONCAT 0.017592191696166992 ARRAY_PUSH 0.01706099510192871
Output for 7.1.13
CONCAT 0.012967109680175781 ARRAY_PUSH 0.010339975357055664
Output for 7.1.12
CONCAT 0.013720035552978516 ARRAY_PUSH 0.014784097671508789
Output for 7.1.11
CONCAT 0.016129016876220703 ARRAY_PUSH 0.015607118606567383
Output for 7.1.10
CONCAT 0.015638113021850586 ARRAY_PUSH 0.013072013854980469
Output for 7.1.9
CONCAT 0.012250185012817383 ARRAY_PUSH 0.011607885360717773
Output for 7.1.8
CONCAT 0.01253199577331543 ARRAY_PUSH 0.010805845260620117
Output for 7.1.7
CONCAT 0.01845097541809082 ARRAY_PUSH 0.017289161682128906
Output for 7.1.6
CONCAT 0.015312910079956055 ARRAY_PUSH 0.00964212417602539
Output for 7.1.5
CONCAT 0.012429952621459961 ARRAY_PUSH 0.010824918746948242
Output for 7.1.4
CONCAT 0.029417991638183594 ARRAY_PUSH 0.009796857833862305
Output for 7.1.3
CONCAT 0.019380807876586914 ARRAY_PUSH 0.02007603645324707
Output for 7.1.2
CONCAT 0.01282191276550293 ARRAY_PUSH 0.01147317886352539
Output for 7.1.1
CONCAT 0.08354401588439941 ARRAY_PUSH 0.011206865310668945
Output for 7.1.0
CONCAT 0.025445938110351562 ARRAY_PUSH 0.02225208282470703
Output for 7.0.33
CONCAT 0.027120113372802734 ARRAY_PUSH 0.034785032272338867
Output for 7.0.32
CONCAT 0.018455982208251953 ARRAY_PUSH 0.016009092330932617
Output for 7.0.31
CONCAT 0.017046928405761719 ARRAY_PUSH 0.015874862670898438
Output for 7.0.30
CONCAT 0.016002893447875977 ARRAY_PUSH 0.015063047409057617
Output for 7.0.29
CONCAT 0.017431974411010742 ARRAY_PUSH 0.018721103668212891
Output for 7.0.28
CONCAT 0.018393039703369141 ARRAY_PUSH 0.01630711555480957
Output for 7.0.27
CONCAT 0.029834985733032227 ARRAY_PUSH 0.031764984130859375
Output for 7.0.26
CONCAT 0.018284082412719727 ARRAY_PUSH 0.049920082092285156
Output for 7.0.25
CONCAT 0.020176887512207031 ARRAY_PUSH 0.026709079742431641
Output for 7.0.24
CONCAT 0.021270036697387695 ARRAY_PUSH 0.015858888626098633
Output for 7.0.23
CONCAT 0.017168045043945312 ARRAY_PUSH 0.032068967819213867
Output for 7.0.22
CONCAT 0.02835392951965332 ARRAY_PUSH 0.030597925186157227
Output for 7.0.21
CONCAT 0.017160892486572266 ARRAY_PUSH 0.017678022384643555
Output for 7.0.20
CONCAT 0.017859935760498047 ARRAY_PUSH 0.015170812606811523
Output for 7.0.19
CONCAT 0.018116950988769531 ARRAY_PUSH 0.017397165298461914
Output for 7.0.18
CONCAT 0.019642829895019531 ARRAY_PUSH 0.016911029815673828
Output for 7.0.17
CONCAT 0.026792049407958984 ARRAY_PUSH 0.016295909881591797
Output for 7.0.16
CONCAT 0.024446964263916016 ARRAY_PUSH 0.034799098968505859
Output for 7.0.15
CONCAT 0.028760910034179688 ARRAY_PUSH 0.030352115631103516
Output for 7.0.14
CONCAT 0.031481027603149414 ARRAY_PUSH 0.02311396598815918
Output for 7.0.13
CONCAT 0.026547908782958984 ARRAY_PUSH 0.031167984008789062
Output for 7.0.12
CONCAT 0.027524948120117188 ARRAY_PUSH 0.028883934020996094
Output for 7.0.11
CONCAT 0.033538103103637695 ARRAY_PUSH 0.044069051742553711
Output for 7.0.10
CONCAT 0.029800176620483398 ARRAY_PUSH 0.029981136322021484
Output for 7.0.9
CONCAT 0.017351865768432617 ARRAY_PUSH 0.015430927276611328
Output for 7.0.8
CONCAT 0.020527839660644531 ARRAY_PUSH 0.017942190170288086
Output for 7.0.7
CONCAT 0.025123834609985352 ARRAY_PUSH 0.019605875015258789
Output for 7.0.6
CONCAT 0.040431022644042969 ARRAY_PUSH 0.030318021774291992
Output for 7.0.5
CONCAT 0.023718118667602539 ARRAY_PUSH 0.027313947677612305
Output for 7.0.4
CONCAT 0.025942087173461914 ARRAY_PUSH 0.035460948944091797
Output for 7.0.3
CONCAT 0.019951820373535156 ARRAY_PUSH 0.020651102066040039
Output for 7.0.2
CONCAT 0.026648044586181641 ARRAY_PUSH 0.01471400260925293
Output for 7.0.1
CONCAT 0.025660037994384766 ARRAY_PUSH 0.027212142944335938
Output for 7.0.0
CONCAT 0.027258872985839844 ARRAY_PUSH 0.016319990158081055
Output for 5.6.40
CONCAT 0.09370112419128418 ARRAY_PUSH 0.1132209300994873
Output for 5.6.39
CONCAT 0.10988211631774902 ARRAY_PUSH 0.12639307975769043
Output for 5.6.38
CONCAT 0.099820137023925781 ARRAY_PUSH 0.065964937210083008
Output for 5.6.37
CONCAT 0.072220087051391602 ARRAY_PUSH 0.068139076232910156
Output for 5.6.36
CONCAT 0.095928192138671875 ARRAY_PUSH 0.061342000961303711
Output for 5.6.35
CONCAT 0.07113194465637207 ARRAY_PUSH 0.098172903060913086
Output for 5.6.34
CONCAT 0.080492973327636719 ARRAY_PUSH 0.10541415214538574
Output for 5.6.33
CONCAT 0.074884891510009766 ARRAY_PUSH 0.13209199905395508
Output for 5.6.32
CONCAT 0.061651945114135742 ARRAY_PUSH 0.066936969757080078
Output for 5.6.31
CONCAT 0.063059806823730469 ARRAY_PUSH 0.071934938430786133
Output for 5.6.30
CONCAT 0.10485315322875977 ARRAY_PUSH 0.1142580509185791
Output for 5.6.29
CONCAT 0.09867095947265625 ARRAY_PUSH 0.10653400421142578
Output for 5.6.28
CONCAT 0.063421964645385742 ARRAY_PUSH 0.070473194122314453
Output for 5.6.27
CONCAT 0.083065986633300781 ARRAY_PUSH 0.10084891319274902
Output for 5.6.26
CONCAT 0.10573816299438477 ARRAY_PUSH 0.11214017868041992
Output for 5.6.25
CONCAT 0.070447921752929688 ARRAY_PUSH 0.072615146636962891
Output for 5.6.24
CONCAT 0.062463998794555664 ARRAY_PUSH 0.071393013000488281
Output for 5.6.23
CONCAT 0.064180850982666016 ARRAY_PUSH 0.068573951721191406
Output for 5.6.22
CONCAT 0.096255064010620117 ARRAY_PUSH 0.12256407737731934
Output for 5.6.21
CONCAT 0.080574989318847656 ARRAY_PUSH 0.078750848770141602
Output for 5.6.20
CONCAT 0.11347293853759766 ARRAY_PUSH 0.096658945083618164
Output for 5.6.19
CONCAT 0.086346864700317383 ARRAY_PUSH 0.11528801918029785
Output for 5.6.18
CONCAT 0.10442996025085449 ARRAY_PUSH 0.085581064224243164
Output for 5.6.17
CONCAT 0.070683956146240234 ARRAY_PUSH 0.090548992156982422
Output for 5.6.16
CONCAT 0.080855846405029297 ARRAY_PUSH 0.067025899887084961
Output for 5.6.15
CONCAT 0.10532093048095703 ARRAY_PUSH 0.10290694236755371
Output for 5.6.14
CONCAT 0.057888984680175781 ARRAY_PUSH 0.070010185241699219
Output for 5.6.13
CONCAT 0.062968015670776367 ARRAY_PUSH 0.073882818222045898
Output for 5.6.12
CONCAT 0.093739032745361328 ARRAY_PUSH 0.064745903015136719
Output for 5.6.11
CONCAT 0.081380844116210938 ARRAY_PUSH 0.099959135055541992
Output for 5.6.10
CONCAT 0.061902999877929688 ARRAY_PUSH 0.067281961441040039
Output for 5.6.9
CONCAT 0.076400041580200195 ARRAY_PUSH 0.072900056838989258
Output for 5.6.8
CONCAT 0.1093590259552002 ARRAY_PUSH 0.062712907791137695
Output for 5.6.7
CONCAT 0.067258119583129883 ARRAY_PUSH 0.11946392059326172
Output for 5.6.6
CONCAT 0.097024202346801758 ARRAY_PUSH 0.061069011688232422
Output for 5.6.5
CONCAT 0.054951906204223633 ARRAY_PUSH 0.070657968521118164
Output for 5.6.4
CONCAT 0.056906938552856445 ARRAY_PUSH 0.06839299201965332
Output for 5.6.3
CONCAT 0.090484857559204102 ARRAY_PUSH 0.075453996658325195
Output for 5.6.2
CONCAT 0.065356016159057617 ARRAY_PUSH 0.096398115158081055
Output for 5.6.1
CONCAT 0.062293052673339844 ARRAY_PUSH 0.069185972213745117
Output for 5.6.0
CONCAT 0.097263097763061523 ARRAY_PUSH 0.068670988082885742
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38
Parse error: syntax error, unexpected '.' in /in/AH1ZX on line 42
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/AH1ZX on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/AH1ZX on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/AH1ZX on line 5
Process exited with code 255.

preferences:
249.29 ms | 401 KiB | 367 Q