jcanker Posted February 27, 2010 Share Posted February 27, 2010 is it possible to use a variable to reference an array key? e.g. $currentstudent = "BillyBob"; $ARRAY['$currentstudent']=40; To make the value be 40 for the array key named BillyBob.. Link to comment https://forums.phpfreaks.com/topic/193598-variable-as-array-key/ Share on other sites More sharing options...
jl5501 Posted February 27, 2010 Share Posted February 27, 2010 yes, but without the quotes Link to comment https://forums.phpfreaks.com/topic/193598-variable-as-array-key/#findComment-1019135 Share on other sites More sharing options...
jcanker Posted February 28, 2010 Author Share Posted February 28, 2010 Awesome! Thank you! Link to comment https://forums.phpfreaks.com/topic/193598-variable-as-array-key/#findComment-1019226 Share on other sites More sharing options...
seventheyejosh Posted February 28, 2010 Share Posted February 28, 2010 yes, but without the quotes Rather, use double quotes, that way if you ever need a literal part, it is useable. ie: $res=mysql_query($query); while($row=mysql_fetch_assoc($res)){ $tempId=$row['id']; if($_REQUEST["fieldNumber$tempId"]>0){ //<-- see here //do something }//end if }//end while Link to comment https://forums.phpfreaks.com/topic/193598-variable-as-array-key/#findComment-1019229 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.