Synergic Posted August 13, 2007 Share Posted August 13, 2007 $months[01] = "Jan"; $months[02] = "Feb"; $months[03] = "Mar"; $i = 02; // also tried "02" echo $months[$i]; The above code has me stumped (echos nothing). Coming from a Java background I've had no such troubles substituting array indices with variables. When i change the $i (in between the brackets) with 02 it appears to work. Any ideas? Link to comment https://forums.phpfreaks.com/topic/64648-arrays-and-using-variables-as-the-index/ Share on other sites More sharing options...
Orio Posted August 13, 2007 Share Posted August 13, 2007 With PHP 5.2.0 I got the output "Feb". But why dont you try it this way (Without the zero): <?php $months[1] = "Jan"; $months[2] = "Feb"; $months[3] = "Mar"; $i = 2; echo $months[$i]; ?> This should work with no probs. Orio. Link to comment https://forums.phpfreaks.com/topic/64648-arrays-and-using-variables-as-the-index/#findComment-322318 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.