using variable variables with arrays please help!

General discussions related to php

Moderators: macek, egami, gesf

sos
New php-forum User
New php-forum User
Posts: 4
Joined: Mon Dec 30, 2002 7:23 pm
Location: Staten Island New York USA

using variable variables with arrays please help!

Postby sos » Mon Dec 30, 2002 7:33 pm

Please can someone show me an easy to follow example of how I can use a dynamic variable with an array. I am having a hard time understanding the practicalities of var variables. I am having a tough time seeing a clear relation on how to use them. all I need is a easy to follow example. thank you.

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Tue Dec 31, 2002 7:00 am

If dynamic means for you from an URL to another, then it is already done.

When you go to a page and you send variables
for example:
mi_page.php?my_var1=26&my_var2=Joan

You can access them using this function:
echo $HTTP_GET_VARS["my_var1"]; (the same as $HTTP_GET_VARS[0] )
would output --> 26
echo $HTTP_GET_VARS["my_var2"]; (the same as $HTTP_GET_VARS[1] )
would output --> Joan

If you have sent those vars using a form and the POST method, then you'll have to use this -->

echo $HTTP_POST_VARS["my_var1"];
would output --> 26
echo $HTTP_POST_VARS["my_var2"];
would output --> Joan

I hope you meant that... :)
otherwise try again ;)

bye!

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Tue Dec 31, 2002 7:12 am

or use $_GET or $_POST arrays =)

sos
New php-forum User
New php-forum User
Posts: 4
Joined: Mon Dec 30, 2002 7:23 pm
Location: Staten Island New York USA

Postby sos » Tue Dec 31, 2002 4:19 pm

You can refer here to the type of variable variable I mean: http://www.zend.com/manual/language.variables.variable.php. What I am failing to comprehend is the usefulness of a VARIABLE VARIABLE. The definition seems very straight forward "a variable variable takes the value of a variable and treats that as the name of a variable". Ok so what I need is some clarity on some practical means in which I can use this tool. Maybe some very basic examples of a variable variable in use.

Please help me see the logic. And Thanks For All The SUPPORT!

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Wed Jan 01, 2003 11:46 pm

Code: Select all

<?php
$test="This is test";
$b="test";
$a=${$b};

echo $a;
?>

output "This is test"


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 0 guests