[SOLVED] Changing Vars
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Changing Vars
How do I do this again... in a brain bubble
I want variables to dynamically change
echo "${$typeofmatch}win";
I want variables to dynamically change
echo "${$typeofmatch}win";
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
does this help??
Sometimes it is convenient to be able to have variable variable names. That is, a variable name which can be set and used dynamically. A normal variable is set with a statement such as:
<?php
$a = "hello";
?>
A variable variable takes the value of a variable and treats that as the name of a variable. In the above example, hello, can be used as the name of a variable by using two dollar signs. i.e.
<?php
$$a = "world";
?>
At this point two variables have been defined and stored in the PHP symbol tree: $a with contents "hello" and $hello with contents "world". Therefore, this statement:
<?php
echo "$a ${$a}";
?>
produces the exact same output as:
<?php
echo "$a $hello";
?>
i.e. they both produce: hello world.
taken from php.net
<?php
$a = "hello";
?>
A variable variable takes the value of a variable and treats that as the name of a variable. In the above example, hello, can be used as the name of a variable by using two dollar signs. i.e.
<?php
$$a = "world";
?>
At this point two variables have been defined and stored in the PHP symbol tree: $a with contents "hello" and $hello with contents "world". Therefore, this statement:
<?php
echo "$a ${$a}";
?>
produces the exact same output as:
<?php
echo "$a $hello";
?>
i.e. they both produce: hello world.
taken from php.net
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
i duno I don't see how I can apply that to
my mind doesnt work today because that is joining strings but this is joining vars .... i duno it makes sense in my mind !!!!!!!!
Code: Select all
<?php
echo ${$typeofmatch}win;
?>
Last edited by John Cartwright on Fri Jul 16, 2004 11:10 pm, edited 1 time in total.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
okay this code is in a function
i havnt done it but it will look like this
i havnt done it but it will look like this
Code: Select all
<?
function matchstats($typeofmatch)
{
while looping database etc etc
{
${$typeofmatch}win = ${typeofmatch}win + 1;
}
echo "${typeofmatch}win";
}
//and then
matchstats("cal"); to call it.
?>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Found my other post: viewtopic.php?t=23718&start=0&postdays= ... hlight=abc*
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
fresh i know what you mean but no...sorry if this is a dumb question but is the echo suppost to echo a db result, depending on what type of match they select, like is the output, the specs of that paticular match???
Feyd: I am completely clueless still.... AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH! sorry for my frustration
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
matchstats($typeofmatch)
{
$z = "{$typeofmatch}win";
global $z;
while looping database etc etc
{
$$z += 1; // maybe ++
}
echo $$z;
}