Array indexing rules ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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..

29th Jun 2016, 5:28 PM
Mukul Vashistha
Mukul Vashistha - avatar
2 Answers
0
first element index is 0 and it's goes upto n-1 index where n is the no. of elements in an array
30th Jun 2016, 9:13 AM
Neelesh Bansal
Neelesh Bansal - avatar
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');
30th May 2017, 11:05 PM
Michal
Michal - avatar