+1

Array indexing rules ?

Is it necessary to have the first index of an array as 0 or do we have some way by which we can assign first array index to be some random number e. g first index as 7 and next element automatically becomes at index 8 and so on..

php

6/29/2016 5:28:09 PM

Mukul Vashistha

2 Answers

New Answer

0

first element index is 0 and it's goes upto n-1 index where n is the no. of elements in an array

0

It's not necessary, you can type: $ar = array(); // empty array $ar[7] = 'a'; // index starts from 7 $ar[] = 'b'; // index = 8 $ar[] = 'c'; // index = 9 or equivalent: $ar = array(7=>'a', 'b', 'c');