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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.