3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['2', 163], ['5', 9] ]; $from = 1; $till = 18; $days = array_column($array, 0); $result = array_map(function($day) use ($array, $days) { return (false!==$key=array_search($day, $days))? $array[$key]: [$day, 0]; },range($from, $till)); var_dump($result);
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
array(18) { [0]=> array(2) { [0]=> int(1) [1]=> int(0) } [1]=> array(2) { [0]=> string(1) "2" [1]=> int(163) } [2]=> array(2) { [0]=> int(3) [1]=> int(0) } [3]=> array(2) { [0]=> int(4) [1]=> int(0) } [4]=> array(2) { [0]=> string(1) "5" [1]=> int(9) } [5]=> array(2) { [0]=> int(6) [1]=> int(0) } [6]=> array(2) { [0]=> int(7) [1]=> int(0) } [7]=> array(2) { [0]=> int(8) [1]=> int(0) } [8]=> array(2) { [0]=> int(9) [1]=> int(0) } [9]=> array(2) { [0]=> int(10) [1]=> int(0) } [10]=> array(2) { [0]=> int(11) [1]=> int(0) } [11]=> array(2) { [0]=> int(12) [1]=> int(0) } [12]=> array(2) { [0]=> int(13) [1]=> int(0) } [13]=> array(2) { [0]=> int(14) [1]=> int(0) } [14]=> array(2) { [0]=> int(15) [1]=> int(0) } [15]=> array(2) { [0]=> int(16) [1]=> int(0) } [16]=> array(2) { [0]=> int(17) [1]=> int(0) } [17]=> array(2) { [0]=> int(18) [1]=> int(0) } }
Output for 5.4.0 - 5.4.45
Fatal error: Call to undefined function array_column() in /in/epdQ4 on line 11
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/epdQ4 on line 3
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/epdQ4 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/epdQ4 on line 3
Process exited with code 255.

preferences:
276.39 ms | 401 KiB | 424 Q