Jump to content

[SOLVED] Simple Question... Please help!


Guest Xanza

Recommended Posts

Guest Xanza

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

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>";
?>

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>";
}
?>

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.