3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php if (!function_exists('array_column')) { function array_column($input, $column_key, $index_key = null) { if ($index_key !== null) { // Collect the keys $keys = array(); $i = 0; // Counter for numerical keys when key does not exist foreach ($input as $row) { if (array_key_exists($index_key, $row)) { // Update counter for numerical keys if (is_numeric($row[$index_key]) || is_bool($row[$index_key])) { $i = max($i, (int) $row[$index_key] + 1); } // Get the key from a single column of the array $keys[] = $row[$index_key]; } else { // The key does not exist, use numerical indexing $keys[] = $i++; } } } if ($column_key !== null) { // Collect the values $values = array(); $i = 0; // Counter for removing keys foreach ($input as $row) { if (array_key_exists($column_key, $row)) { // Get the values from a single column of the input array $values[] = $row[$column_key]; $i++; } elseif (isset($keys)) { // Values does not exist, also drop the key for it array_splice($keys, $i, 1); } } } else { // Get the full arrays $values = array_values($input); } if ($index_key !== null) { return array_combine($keys, $values); } return $values; } echo "Custom array_column()"; } $records = array( array( 'id' => 2135, 'first_name' => 'John', 'last_name' => 'Doe', ), array( 'id' => 3245, 'first_name' => 'Sally', 'last_name' => 'Smith', ), array( 'id' => 5342, 'first_name' => 'Jane', 'last_name' => 'Jones', ), array( 'id' => 5623, 'first_name' => 'Peter', 'last_name' => 'Doe', ) ); $start = microtime(true); for ($i=0;$i<9999;$i++) { array_column($records, 'first_name'); } $end = microtime(true); echo $end-$start."\n";
Output for 7.1.0
0.0014548301696777
Output for 7.0.14
0.0026781558990479
Output for 7.0.10
0.0015518665313721
Output for 7.0.9
0.002316951751709
Output for 7.0.8
0.0018270015716553
Output for 7.0.7
0.0024921894073486
Output for 7.0.6
0.0017220973968506
Output for 7.0.5
0.0019171237945557
Output for 7.0.4
0.0020689964294434
Output for 7.0.3
0.0023369789123535
Output for 7.0.2
0.0023200511932373
Output for 7.0.1
0.0023670196533203
Output for 7.0.0
0.0016269683837891
Output for 5.6.28
0.0053789615631104
Output for 5.6.25
0.0076708793640137
Output for 5.6.24
0.0034310817718506
Output for 5.6.23
0.0052239894866943
Output for 5.6.22
0.0050959587097168
Output for 5.6.21
0.0036759376525879
Output for 5.6.20
0.0075488090515137
Output for 5.6.19
0.0041301250457764
Output for 5.6.18
0.0048739910125732
Output for 5.6.17
0.0036730766296387
Output for 5.6.16
0.0040631294250488
Output for 5.6.15
0.0035638809204102
Output for 5.6.14
0.0049090385437012
Output for 5.6.13
0.0033371448516846
Output for 5.6.12
0.0036721229553223
Output for 5.6.11
0.0046288967132568
Output for 5.6.10
0.0034949779510498
Output for 5.6.9
0.0037710666656494
Output for 5.6.8
0.0035510063171387
Output for 5.6.7
0.0037989616394043
Output for 5.6.6
0.0039899349212646
Output for 5.6.5
0.003756046295166
Output for 5.6.4
0.0042800903320312
Output for 5.6.3
0.0059158802032471
Output for 5.6.2
0.0039360523223877
Output for 5.6.1
0.0051369667053223
Output for 5.6.0
0.0046229362487793
Output for 5.5.38
0.0042791366577148
Output for 5.5.37
0.0051360130310059
Output for 5.5.36
0.003648042678833
Output for 5.5.35
0.0042409896850586
Output for 5.5.0, 5.5.34
0.005073070526123
Output for 5.5.33
0.0036931037902832
Output for 5.5.32
0.0046329498291016
Output for 5.5.31
0.0044310092926025
Output for 5.5.30
0.0040748119354248
Output for 5.5.29
0.0047109127044678
Output for 5.5.28
0.0038421154022217
Output for 5.5.27
0.0043478012084961
Output for 5.5.26
0.0035860538482666
Output for 5.5.25
0.0050439834594727
Output for 5.5.24
0.0046138763427734
Output for 5.5.23
0.0044760704040527
Output for 5.5.22
0.0035920143127441
Output for 5.5.21
0.0049810409545898
Output for 5.5.20
0.0042288303375244
Output for 5.5.19
0.0043070316314697
Output for 5.5.18
0.005108118057251
Output for 5.5.16
0.0038301944732666
Output for 5.5.15
0.004180908203125
Output for 5.5.14
0.0053901672363281
Output for 5.5.13
0.0053031444549561
Output for 5.5.12
0.0051350593566895
Output for 5.5.11
0.0046241283416748
Output for 5.5.10
0.0045850276947021
Output for 5.5.9
0.0045831203460693
Output for 5.5.8
0.0038959980010986
Output for 5.5.7
0.0048038959503174
Output for 5.5.6
0.0055351257324219
Output for 5.5.5
0.0070991516113281
Output for 5.5.4
0.0055019855499268
Output for 5.5.3
0.0044879913330078
Output for 5.5.2
0.0042281150817871
Output for 5.5.1
0.0044059753417969
Output for 5.4.45
Custom array_column()0.012425184249878
Output for 5.4.44
Custom array_column()0.016932964324951
Output for 5.4.43
Custom array_column()0.018682956695557
Output for 5.4.42
Custom array_column()0.017542839050293
Output for 5.4.41
Custom array_column()0.019052028656006
Output for 5.4.40
Custom array_column()0.015533208847046
Output for 5.4.39
Custom array_column()0.019205093383789
Output for 5.4.38
Custom array_column()0.019263982772827
Output for 5.4.37
Custom array_column()0.01499605178833
Output for 5.4.36
Custom array_column()0.01932692527771
Output for 5.4.35
Custom array_column()0.017025947570801
Output for 5.4.34
Custom array_column()0.017531156539917
Output for 5.4.32
Custom array_column()0.025148868560791
Output for 5.4.31
Custom array_column()0.013916969299316
Output for 5.4.30
Custom array_column()0.021178007125854
Output for 5.4.29
Custom array_column()0.020019054412842
Output for 5.4.28
Custom array_column()0.016079902648926
Output for 5.4.27
Custom array_column()0.020731925964355
Output for 5.4.26
Custom array_column()0.020828008651733
Output for 5.4.25
Custom array_column()0.020960807800293
Output for 5.4.24
Custom array_column()0.018261909484863
Output for 5.4.23
Custom array_column()0.016896963119507
Output for 5.4.22
Custom array_column()0.021013021469116
Output for 5.4.21
Custom array_column()0.015816926956177
Output for 5.4.20
Custom array_column()0.012788057327271
Output for 5.4.19
Custom array_column()0.016718864440918
Output for 5.4.18
Custom array_column()0.017870903015137
Output for 5.4.17
Custom array_column()0.02082896232605
Output for 5.4.16
Custom array_column()0.017514944076538
Output for 5.4.15
Custom array_column()0.016041040420532
Output for 5.4.14
Custom array_column()0.015506982803345
Output for 5.4.13
Custom array_column()0.01862907409668
Output for 5.4.12
Custom array_column()0.020478963851929
Output for 5.4.11
Custom array_column()0.017912149429321
Output for 5.4.10
Custom array_column()0.016473054885864
Output for 5.4.9
Custom array_column()0.026912927627563
Output for 5.4.8
Custom array_column()0.017282009124756
Output for 5.4.1, 5.4.7
Custom array_column()0.018467903137207
Output for 5.4.6
Custom array_column()0.017119884490967
Output for 5.4.5
Custom array_column()0.018434047698975
Output for 5.4.4
Custom array_column()0.014552116394043
Output for 5.4.3
Custom array_column()0.021111965179443
Output for 5.4.2
Custom array_column()0.020035982131958
Output for 5.4.0
Custom array_column()0.013759136199951
Output for 5.3.29
Custom array_column()0.022507905960083
Output for 5.3.28
Custom array_column()0.02531099319458
Output for 5.3.27
Custom array_column()0.021991014480591
Output for 5.3.26
Custom array_column()0.018512010574341
Output for 5.3.25
Custom array_column()0.019678831100464
Output for 5.3.24
Custom array_column()0.02184796333313
Output for 5.3.23
Custom array_column()0.018097877502441
Output for 5.3.22
Custom array_column()0.019556045532227
Output for 5.3.21
Custom array_column()0.016930103302002
Output for 5.3.20
Custom array_column()0.019706010818481
Output for 5.3.19
Custom array_column()0.024407863616943
Output for 5.3.18
Custom array_column()0.019855976104736
Output for 5.3.17
Custom array_column()0.0189049243927
Output for 5.3.16
Custom array_column()0.022310972213745
Output for 5.3.15
Custom array_column()0.023606061935425
Output for 5.3.14
Custom array_column()0.021832942962646
Output for 5.3.13
Custom array_column()0.017776012420654
Output for 5.3.12
Custom array_column()0.024333953857422
Output for 5.3.11
Custom array_column()0.022008180618286
Output for 5.3.10
Custom array_column()0.023196935653687
Output for 5.3.9
Custom array_column()0.023234128952026
Output for 5.3.8
Custom array_column()0.025896072387695
Output for 5.3.7
Custom array_column()0.023597955703735
Output for 5.3.6
Custom array_column()0.021831035614014
Output for 5.3.5
Custom array_column()0.020628213882446
Output for 5.3.4
Custom array_column()0.020455121994019
Output for 5.3.3
Custom array_column()0.020145893096924
Output for 5.3.2
Custom array_column()0.020320177078247
Output for 5.3.1
Custom array_column()0.018594980239868
Output for 5.3.0
Custom array_column()0.022268056869507
Output for 5.2.17
Custom array_column()0.029055118560791
Output for 5.2.16
Custom array_column()0.021745920181274
Output for 5.2.15
Custom array_column()0.03172492980957
Output for 5.2.14
Custom array_column()0.032149076461792
Output for 5.2.13
Custom array_column()0.02790379524231
Output for 5.2.12
Custom array_column()0.02816915512085
Output for 5.2.11
Custom array_column()0.020658016204834
Output for 5.2.10
Custom array_column()0.031383991241455
Output for 5.2.9
Custom array_column()0.022254943847656
Output for 5.2.8
Custom array_column()0.032010793685913
Output for 5.2.7
Custom array_column()0.036508798599243
Output for 5.2.6
Custom array_column()0.031072854995728
Output for 5.2.5
Custom array_column()0.031580924987793
Output for 5.2.4
Custom array_column()0.031742811203003
Output for 5.2.3
Custom array_column()0.027549982070923
Output for 5.2.2
Custom array_column()0.027533054351807
Output for 5.2.1
Custom array_column()0.026484966278076
Output for 5.2.0
Custom array_column()0.024834156036377
Output for 5.1.6
Custom array_column()0.021614074707031
Output for 5.1.5
Custom array_column()0.022170066833496
Output for 5.1.4
Custom array_column()0.03351092338562
Output for 5.1.3
Custom array_column()0.027212858200073
Output for 5.1.2
Custom array_column()0.034812927246094
Output for 5.1.1
Custom array_column()0.032065153121948
Output for 5.1.0
Custom array_column()0.034459829330444
Output for 5.0.5
Custom array_column()0.060537099838257
Output for 5.0.4
Custom array_column()0.054280042648315
Output for 5.0.3
Custom array_column()0.053253173828125
Output for 5.0.2
Custom array_column()0.053536176681519
Output for 5.0.1
Custom array_column()0.063621997833252
Output for 5.0.0
Custom array_column()0.054894924163818
Output for 4.4.9
Custom array_column()0.057678
Output for 4.4.8
Custom array_column()0.068591
Output for 4.4.7
Custom array_column()0.043113
Output for 4.4.6
Custom array_column()0.065808
Output for 4.4.5
Custom array_column()0.051794
Output for 4.4.4
Custom array_column()0.065918
Output for 4.4.3
Custom array_column()0.056982
Output for 4.4.2
Custom array_column()0.073023
Output for 4.4.1
Custom array_column()0.070624
Output for 4.4.0
Custom array_column()0.058006
Output for 4.3.11
Custom array_column()0.051489
Output for 4.3.10
Custom array_column()0.067074
Output for 4.3.9
Custom array_column()0.055201
Output for 4.3.8
Custom array_column()0.06742
Output for 4.3.7
Custom array_column()0.057856
Output for 4.3.6
Custom array_column()0.051382
Output for 4.3.5
Custom array_column()0.066489
Output for 4.3.4
Custom array_column()0.04838
Output for 4.3.3
Custom array_column()0.058593
Output for 4.3.2
Custom array_column()0.062823
Output for 4.3.1
Custom array_column()0.065588
Output for 4.3.0
Custom array_column()0.066562