how to array key start from 1 instead of 0?

2019-03-06 20:01发布

问题:

How do I start the array of a range at 1 instead of 0, Code looks like this:

    $numbers = range(0, 14);

I tried this but that does not solve my problem

    $numbers = range(0, 14);

回答1:

You can also go for :

$numbers = range(0, 14);

array_unshift($numbers,"");
unset($numbers[0]);


回答2:

You could try this:

$numbers = array_combine(range(1,14), range(1,14));


回答3:

Try this code These will help you

$data = array_slice(range(0,12), 1, null, true);


标签: php arrays range