Reputation: 139
<?php
$number = range(0,5);
print_r ($number);
?>
Above code work , but what if the data is 'ABC001' to 'ABC010' ? I tried with
$number = range('ABC001','ABC010');
it only return 'A' , any idea how do i do it ? or missing out anything ?
Upvotes: 1
Views: 223
Reputation: 19780
Another way, using hexdec()
, dechex()
and array_map()
.
$range = array_map('dechex', range(hexdec('ABC001'), hexdec('ABC010')));
Upvotes: 0
Reputation: 146450
Arithmetic operations on character variables don't work with the range() function:
Character sequence values are limited to a length of one. If a length greater than one is entered, only the first character is used.
You need to roll your own code, e.g.:
$from = 'ABC001';
$to = 'ABC010';
$range = [];
for ($i = $from; $i <= $to; $i++) {
$range[] = $i;
}
var_dump($range);
Upvotes: 3