ballhogjoni Posted September 2, 2008 Share Posted September 2, 2008 I have an illegal offset warning do to this foreach loop: foreach($aAvailableMonthsDates as $key=>$sStartDate){ $aAvailableMonths[$sStartDate] = date("F - Y", strtotime($sStartDate)); } if I add single quotes around the index in the $aAvailableMonths array the warning goes away. My question is if I do that will it affect the actual value if the $sStartDate. What I mean is will the index now be a string that equals $sStartDate or will it actually be the value of the $sStartDate variable? IE, can I do this with out any problems occuring: foreach($aAvailableMonthsDates as $key=>$sStartDate){ $aAvailableMonths['$sStartDate'] = date("F - Y", strtotime($sStartDate)); } Link to comment https://forums.phpfreaks.com/topic/122440-illegal-offset-question/ Share on other sites More sharing options...
webxan Posted September 2, 2008 Share Posted September 2, 2008 using single quote it will treat it as string. and might not be the correct for logic. Link to comment https://forums.phpfreaks.com/topic/122440-illegal-offset-question/#findComment-632200 Share on other sites More sharing options...
ballhogjoni Posted September 2, 2008 Author Share Posted September 2, 2008 can I use double quotes then? Link to comment https://forums.phpfreaks.com/topic/122440-illegal-offset-question/#findComment-632203 Share on other sites More sharing options...
discomatt Posted September 2, 2008 Share Posted September 2, 2008 Are you sure you don't want this instead? foreach($aAvailableMonthsDates as $key=>$sStartDate){ $aAvailableMonths[$key] = date("F - Y", strtotime($sStartDate)); } Link to comment https://forums.phpfreaks.com/topic/122440-illegal-offset-question/#findComment-632212 Share on other sites More sharing options...
ballhogjoni Posted September 2, 2008 Author Share Posted September 2, 2008 Yep, someone else wrote the code, it works, I just don't want to change anything like that. Link to comment https://forums.phpfreaks.com/topic/122440-illegal-offset-question/#findComment-632224 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.