3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $days = []; $searchData = ['dat' => '2015-11-13']; $offset = 3; $now = date_create(); if (date_create($searchData['dat'])->modify('- '. $offset .' days') < $now) { $offsetStart = -1 * date_create($searchData['dat'])->diff($now)->format('%a'); } else { $offsetStart = -1 * $offset; } $offsetEnd = 2 * $offset + $offsetStart; for ($i = $offsetStart; $i <= $offsetEnd; $i++) { $days[] = $i; } print_r($days);
based on mJMZJ
Output for 5.4.9 - 5.4.45, 5.6.28, 7.0.20 - 7.2.0
Array ( [0] => -2 [1] => -1 [2] => 0 [3] => 1 [4] => 2 [5] => 3 [6] => 4 )
Output for 7.0.6
Array ( [0] => -172 [1] => -171 [2] => -170 [3] => -169 [4] => -168 [5] => -167 [6] => -166 )
Output for 7.0.5
Array ( [0] => -142 [1] => -141 [2] => -140 [3] => -139 [4] => -138 [5] => -137 [6] => -136 )
Output for 7.0.4
Array ( [0] => -118 [1] => -117 [2] => -116 [3] => -115 [4] => -114 [5] => -113 [6] => -112 )
Output for 7.0.3
Array ( [0] => -126 [1] => -125 [2] => -124 [3] => -123 [4] => -122 [5] => -121 [6] => -120 )
Output for 7.0.2
Array ( [0] => -131 [1] => -130 [2] => -129 [3] => -128 [4] => -127 [5] => -126 [6] => -125 )
Output for 7.0.1
Array ( [0] => -132 [1] => -131 [2] => -130 [3] => -129 [4] => -128 [5] => -127 [6] => -126 )
Output for 7.0.0
Array ( [0] => -135 [1] => -134 [2] => -133 [3] => -132 [4] => -131 [5] => -130 [6] => -129 )
Output for 5.6.21
Array ( [0] => -171 [1] => -170 [2] => -169 [3] => -168 [4] => -167 [5] => -166 [6] => -165 )
Output for 5.6.20
Array ( [0] => -149 [1] => -148 [2] => -147 [3] => -146 [4] => -145 [5] => -144 [6] => -143 )
Output for 5.6.19
Array ( [0] => -116 [1] => -115 [2] => -114 [3] => -113 [4] => -112 [5] => -111 [6] => -110 )
Output for 5.6.18
Array ( [0] => -123 [1] => -122 [2] => -121 [3] => -120 [4] => -119 [5] => -118 [6] => -117 )
Output for 5.6.17
Array ( [0] => -127 [1] => -126 [2] => -125 [3] => -124 [4] => -123 [5] => -122 [6] => -121 )
Output for 5.6.16
Array ( [0] => -136 [1] => -135 [2] => -134 [3] => -133 [4] => -132 [5] => -131 [6] => -130 )
Output for 5.6.15
Array ( [0] => -137 [1] => -136 [2] => -135 [3] => -134 [4] => -133 [5] => -132 [6] => -131 )
Output for 5.6.14
Array ( [0] => -141 [1] => -140 [2] => -139 [3] => -138 [4] => -137 [5] => -136 [6] => -135 )
Output for 5.6.13
Array ( [0] => -154 [1] => -153 [2] => -152 [3] => -151 [4] => -150 [5] => -149 [6] => -148 )
Output for 5.6.12
Array ( [0] => -159 [1] => -158 [2] => -157 [3] => -156 [4] => -155 [5] => -154 [6] => -153 )
Output for 5.6.11
Array ( [0] => -163 [1] => -162 [2] => -161 [3] => -160 [4] => -159 [5] => -158 [6] => -157 )
Output for 5.6.10
Array ( [0] => -164 [1] => -163 [2] => -162 [3] => -161 [4] => -160 [5] => -159 [6] => -158 )
Output for 5.6.9
Array ( [0] => -166 [1] => -165 [2] => -164 [3] => -163 [4] => -162 [5] => -161 [6] => -160 )
Output for 5.6.8
Array ( [0] => -169 [1] => -168 [2] => -167 [3] => -166 [4] => -165 [5] => -164 [6] => -163 )
Output for 5.5.35
Array ( [0] => -191 [1] => -190 [2] => -189 [3] => -188 [4] => -187 [5] => -186 [6] => -185 )
Output for 5.5.34
Array ( [0] => -150 [1] => -149 [2] => -148 [3] => -147 [4] => -146 [5] => -145 [6] => -144 )
Output for 5.5.33
Array ( [0] => -117 [1] => -116 [2] => -115 [3] => -114 [4] => -113 [5] => -112 [6] => -111 )
Output for 5.5.32
Array ( [0] => -125 [1] => -124 [2] => -123 [3] => -122 [4] => -121 [5] => -120 [6] => -119 )
Output for 5.5.31
Array ( [0] => -129 [1] => -128 [2] => -127 [3] => -126 [4] => -125 [5] => -124 [6] => -123 )
Output for 5.5.30
Array ( [0] => -140 [1] => -139 [2] => -138 [3] => -137 [4] => -136 [5] => -135 [6] => -134 )
Output for 5.5.29
Array ( [0] => -156 [1] => -155 [2] => -154 [3] => -153 [4] => -152 [5] => -151 [6] => -150 )
Output for 5.5.28
Array ( [0] => -160 [1] => -159 [2] => -158 [3] => -157 [4] => -156 [5] => -155 [6] => -154 )
Output for 5.5.27
Array ( [0] => -161 [1] => -160 [2] => -159 [3] => -158 [4] => -157 [5] => -156 [6] => -155 )
Output for 5.5.26
Array ( [0] => -165 [1] => -164 [2] => -163 [3] => -162 [4] => -161 [5] => -160 [6] => -159 )
Output for 5.5.25
Array ( [0] => -168 [1] => -167 [2] => -166 [3] => -165 [4] => -164 [5] => -163 [6] => -162 )
Output for 5.5.24
Array ( [0] => -193 [1] => -192 [2] => -191 [3] => -190 [4] => -189 [5] => -188 [6] => -187 )
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/e0voh on line 3
Process exited with code 255.