[SOLVED] Changing Vars

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Changing Vars

Post by John Cartwright »

How do I do this again... in a brain bubble

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

Post by d3ad1ysp0rk »

echo ${$typeofmatch}win;

Maybe?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in C:\apachefriends\xampp\htdocs\templates\template19\index.php on line 81
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Sorry, not too good at this, a few people are knowledgable on this type of thing though.. but they're all asleep :P
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

who the hell sleeps when there is coding to be done! :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I had a post recently about this..
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

mind sharing?

i couldnt find what you were talking about feyd
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

does this help??

Post by fresh »

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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

i duno I don't see how I can apply that to

Code: Select all

<?php

echo ${$typeofmatch}win;

?>
my mind doesnt work today because that is joining strings but this is joining vars .... i duno it makes sense in my mind !!!!!!!!
Last edited by John Cartwright on Fri Jul 16, 2004 11:10 pm, edited 1 time in total.
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

Post by fresh »

whats the output suppost to look like:

blah win ???
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

okay this code is in a function

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.

?>
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

Post by fresh »

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

if so, just give each link it's own value and compare when passed... not sure if that would even work... gd lk :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

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???
fresh i know what you mean but no...


Feyd: I am completely clueless still.... AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH! sorry for my frustration
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

matchstats($typeofmatch) 
{ 
     $z = "{$typeofmatch}win";
     global $z;
     while looping database etc etc 
     { 
          $$z += 1;  // maybe ++
     } 
      
     echo $$z; 
}
maybe.... :?
Post Reply