Page 1 of 2

Changing Vars

Posted: Fri Jul 16, 2004 10:43 pm
by John Cartwright
How do I do this again... in a brain bubble

I want variables to dynamically change


echo "${$typeofmatch}win";

Posted: Fri Jul 16, 2004 10:44 pm
by d3ad1ysp0rk
echo ${$typeofmatch}win;

Maybe?

Posted: Fri Jul 16, 2004 10:46 pm
by John Cartwright
Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in C:\apachefriends\xampp\htdocs\templates\template19\index.php on line 81

Posted: Fri Jul 16, 2004 10:51 pm
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

Posted: Fri Jul 16, 2004 10:54 pm
by John Cartwright
who the hell sleeps when there is coding to be done! :)

Posted: Fri Jul 16, 2004 10:59 pm
by feyd
I had a post recently about this..

Posted: Fri Jul 16, 2004 11:03 pm
by John Cartwright
mind sharing?

i couldnt find what you were talking about feyd

does this help??

Posted: Fri Jul 16, 2004 11:05 pm
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

Posted: Fri Jul 16, 2004 11:07 pm
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 !!!!!!!!

Posted: Fri Jul 16, 2004 11:10 pm
by fresh
whats the output suppost to look like:

blah win ???

Posted: Fri Jul 16, 2004 11:15 pm
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.

?>

Posted: Fri Jul 16, 2004 11:20 pm
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 :)

Posted: Fri Jul 16, 2004 11:21 pm
by feyd

Posted: Fri Jul 16, 2004 11:23 pm
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

Posted: Fri Jul 16, 2004 11:28 pm
by feyd

Code: Select all

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