Lucky2710 Posted July 30, 2010 Share Posted July 30, 2010 This might be a dumb question but it would be helpful. Is there anyway to make an array not start at "0"? Quote Link to comment https://forums.phpfreaks.com/topic/209298-is-there-anyway-to-make-an-array-not-start-at-0/ Share on other sites More sharing options...
trq Posted July 30, 2010 Share Posted July 30, 2010 No. Quote Link to comment https://forums.phpfreaks.com/topic/209298-is-there-anyway-to-make-an-array-not-start-at-0/#findComment-1092888 Share on other sites More sharing options...
Lucky2710 Posted July 30, 2010 Author Share Posted July 30, 2010 Well dang it would make my code less confusing! cause im using dbs with a bunch of #s! Quote Link to comment https://forums.phpfreaks.com/topic/209298-is-there-anyway-to-make-an-array-not-start-at-0/#findComment-1092892 Share on other sites More sharing options...
jcbones Posted July 30, 2010 Share Posted July 30, 2010 <?php for($i = 1; $i < 10; $i++) { $flip[$i] = 'Yes'; } echo '<pre>'; print_r($flip); echo '</pre>'; ?> Outputs Array ( [1] => Yes [2] => Yes [3] => Yes [4] => Yes [5] => Yes [6] => Yes [7] => Yes [8] => Yes [9] => Yes ) Quote Link to comment https://forums.phpfreaks.com/topic/209298-is-there-anyway-to-make-an-array-not-start-at-0/#findComment-1092893 Share on other sites More sharing options...
PFMaBiSmAd Posted July 30, 2010 Share Posted July 30, 2010 You could also create a dummy zero'th element, then remove it after the other elements have been added. Quote Link to comment https://forums.phpfreaks.com/topic/209298-is-there-anyway-to-make-an-array-not-start-at-0/#findComment-1092896 Share on other sites More sharing options...
Alex Posted July 30, 2010 Share Posted July 30, 2010 You could use array_unshift to prepend a useless item to the front of the array. I wouldn't recommend it though. The reason 0 was chosen for the start of array indexes is because it's typically more useful and less confusing. Quote Link to comment https://forums.phpfreaks.com/topic/209298-is-there-anyway-to-make-an-array-not-start-at-0/#findComment-1092899 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.