1
votes

I have a case where I need to check if a variable is in array and since more and more data is added I may need to assign two or more ranges of numbers to a variable for the check.

I tried appending another range to the variable and I also tried array_merge().

$x = range(0,10);
$y = range(15,30);
$z = array_merge($x, $y);
print_r($z);

Is there a more convenient way to keep the variable name $x rather than having to add each additional range with another variable ($y) then merging it with $x and assigning yet another variable ($z) to the array_merge()?

I need something like $x is in range of both numbers from 0 to 10 but also from 15 to 30 without the extra math?

$x = range(0,10);
$x .= range(15,30);
...

Thank you!

1

1 Answers

1
votes

You can merge the original range() with the new range, and assign it back to $x. You do not have to give it a new name for every new value it gets, you can overwrite the value instead.

$x = range(0,10);
$x = array_merge($x, range(15,30));
print_r($x);