?

Search Help Board

PHP FAQ
PHP Articles
PHP Help
Bulletin Board

PHP Manual (NEW!)
First Time PHP'ers
Help with programming
Sql assignment help
PHP Homework Help


C# Help

?
?Re: accessing array using address variables
Author:??(---.capfed2.sinectis.com.ar)
Date:???10-24-03 22:28

$int0="January";
$int1="February";
$int2="March";
$array1=array();
$ins="int";
$ins1="";
$ins2="";
$i=0;
for ($i=0;$i<3;$i++){
$ins1="int" . $i;
$ins2 = $ins1;
// notice the double dollar ($$)
$array1[$i]=$$ins1;
print("$ins2
");
}
?>

this is easier than explaining

$age=21;
$var_name="age";

echo $$var_name; // returns 21
echo ${"ag" . "e"}; // the same as above

but for this case its better like this:

$months = array(null, "Jan", "Feb", ..., "Dec");
// january is not month zero!

echo $months[5]; // returns "May"

or even easier:

echo date("F", mktime(0, 0, 0, 12, 0, 0)); // returns "December"

see php.net

?Topics Author? Date
?accessing array using address variables??new
jan 10-14-03 21:26?
?Re: accessing array using address variables??new
federico 10-24-03 22:28?
Go to Top??|??Go to Topic??|??Flat View??|??Search?
??|??
New Topic
?Reply To This Message
?Your Name:
?Your Email:
?Subject:
Email replies to this thread, to the address above.
????

Provided By
Phorum