Jump to content

arrays and using variables as the index


Synergic

Recommended Posts


        $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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.