Home > Back-end >  PHP How to fill up variable with range() and extra numbers
PHP How to fill up variable with range() and extra numbers

Time:09-25


I need to fill up an variable with *range* and some extra numbers. So my variable should have numbers `101-167, `201-245` `255`. For one range is easy, but can't figure out to add extra numbers:
$i = range(101,167) ??

Then I also have a case that I need to remove few numbers 301-351, but take out 329 and 340. Do I just make several ranges like 301-218, 330-339, 341-351?
Thanks

CodePudding user response:

Use array_merge() to concatenate multiple arrays.

$multi_ranges = array_merge(range(101, 167), range(201, 245), [255]);
  • Related