user4368069
user4368069

Reputation:

Array with multiple numerical ranges

If I have multiple numerical ranges I need to put into an array (i.e. 1-14 and 21-30), how would I do this?

PHP has range(), but it only handles one range: http://php.net/manual/en/function.range.php

Upvotes: 0

Views: 1283

Answers (3)

RaMeSh
RaMeSh

Reputation: 3424

Try with below code:

<?php
$number = range(0,14);
$num= range(21,30);
$array = array_merge($number , $num );
print_r ($array );
?>

Here is Demo

For your reference Reference Link

Upvotes: 0

Sougata Bose
Sougata Bose

Reputation: 31739

Here is the solution -

$array = array_merge(range(1, 14), range(21, 30));

DEMO

Upvotes: 1

user4294557
user4294557

Reputation:

$alphas = array_merge(range('A', 'Z'), range('a', 'z'));

refer Way to get all alphabetic chars in an array in PHP?

Upvotes: 2

Related Questions