3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $ranges = explode(',', '221-231,232-242,243-253,254-264,265-275,276-286,287-297,298-308,309-319,320-330,331-341,342-352'); $rackIds = array(); foreach($ranges as $range) { $racks = explode('-', $range); $start = $racks[0]; $end = $racks[1]; for ($i = $start; $i <= $end; $i++) { $rackIds[] = $i; } } print_r($rackIds);
Output for 4.3.0 - 7.1.0
Array ( [0] => 221 [1] => 222 [2] => 223 [3] => 224 [4] => 225 [5] => 226 [6] => 227 [7] => 228 [8] => 229 [9] => 230 [10] => 231 [11] => 232 [12] => 233 [13] => 234 [14] => 235 [15] => 236 [16] => 237 [17] => 238 [18] => 239 [19] => 240 [20] => 241 [21] => 242 [22] => 243 [23] => 244 [24] => 245 [25] => 246 [26] => 247 [27] => 248 [28] => 249 [29] => 250 [30] => 251 [31] => 252 [32] => 253 [33] => 254 [34] => 255 [35] => 256 [36] => 257 [37] => 258 [38] => 259 [39] => 260 [40] => 261 [41] => 262 [42] => 263 [43] => 264 [44] => 265 [45] => 266 [46] => 267 [47] => 268 [48] => 269 [49] => 270 [50] => 271 [51] => 272 [52] => 273 [53] => 274 [54] => 275 [55] => 276 [56] => 277 [57] => 278 [58] => 279 [59] => 280 [60] => 281 [61] => 282 [62] => 283 [63] => 284 [64] => 285 [65] => 286 [66] => 287 [67] => 288 [68] => 289 [69] => 290 [70] => 291 [71] => 292 [72] => 293 [73] => 294 [74] => 295 [75] => 296 [76] => 297 [77] => 298 [78] => 299 [79] => 300 [80] => 301 [81] => 302 [82] => 303 [83] => 304 [84] => 305 [85] => 306 [86] => 307 [87] => 308 [88] => 309 [89] => 310 [90] => 311 [91] => 312 [92] => 313 [93] => 314 [94] => 315 [95] => 316 [96] => 317 [97] => 318 [98] => 319 [99] => 320 [100] => 321 [101] => 322 [102] => 323 [103] => 324 [104] => 325 [105] => 326 [106] => 327 [107] => 328 [108] => 329 [109] => 330 [110] => 331 [111] => 332 [112] => 333 [113] => 334 [114] => 335 [115] => 336 [116] => 337 [117] => 338 [118] => 339 [119] => 340 [120] => 341 [121] => 342 [122] => 343 [123] => 344 [124] => 345 [125] => 346 [126] => 347 [127] => 348 [128] => 349 [129] => 350 [130] => 351 [131] => 352 )