Guest Xanza Posted May 26, 2007 Share Posted May 26, 2007 I have a little bit of a question, and thought that I would come see the experts! <? $_one['Zach'] = "18"; $_one['Jeff'] = "17"; $_one['Ducky'] = "19"; $_one['Brian'] = "21"; $_one['Samantha'] = "16"; foreach($_one as $key => $value){ echo "$key is $value years old!" . "<br>"; } ?> I've just started playing with foreach() and I have a question. Dispite this being a stupid script, and it doing nothing, is their a way for me to add another $value? Such as adding a Variable Variable? Like having <? $_one['Zach'] = "18","Mainesburg"; $_one['Jeff'] = "17","Mainesburg"; $_one['Ducky'] = "19","Mansfield"; $_one['Brian'] = "21","Rochester"; $_one['Samantha'] = "16","Williamsport"; foreach($_one as $key => $value){ echo "$key is $value years old, and lives in ${$value}!" . "<br>"; } ?> Any help will be apprecieated! Link to comment https://forums.phpfreaks.com/topic/53072-solved-simple-question-please-help/ Share on other sites More sharing options...
egorig Posted May 26, 2007 Share Posted May 26, 2007 Hope you like it <? $_one['Zach'][] = "18"; $_one['Zach'][] = "Mainesburg"; $_one['Jeff'][] = "17"; $_one['Jeff'][] = "Mainesburg"; $_one['Ducky'][] = "19"; $_one['Ducky'][] = "Mansfield"; foreach($_one as $key => $value) echo "$key is $value[0] years old, and lives in $value[1]!" . "<br>"; ?> Link to comment https://forums.phpfreaks.com/topic/53072-solved-simple-question-please-help/#findComment-262206 Share on other sites More sharing options...
taith Posted May 26, 2007 Share Posted May 26, 2007 yes... but not like that <?php $_one[1][name]="Zach"; $_one[1][age]="18"; $_one[1][location]="Mainesburg"; $_one[2][name]= "Jeff"; $_one[2][age]= "17"; $_one[2][location]="Mainesburg"; foreach($_one as $k=>$v){ echo "$_one[$k][name] is $_one[$k][age] years old, and lives in $_one[$k][location]<br>"; } ?> Link to comment https://forums.phpfreaks.com/topic/53072-solved-simple-question-please-help/#findComment-262212 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.