[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:

Post by John Cartwright »

that looks like it will work :)

but this {} business is going to be used elsewhere on my site...

is there not a way to simply do ${$var}var2;
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I don't think so.. at least without combining them together partly before hand like:

Code: Select all

<?php

$var = "something";
$somethingvar2 = "wicked";
$something = "jelly";
$jellyvar2 = "juice";

echo ${"{$var}var2"};

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

Post by John Cartwright »

yea thats what i needed :)
ty feyd lemme try it

edit: wait i see what u mean..

ill let u know on the results
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

<?php
	function matchstats($league)
	{
	//".$config->getcal()."
		$cal = mysql_query("SELECT * FROM matches WHERE league='cal-invite'");
	
		while ($record = mysql_fetch_array($cal))
		{
			switch ($record["outcome"]) :
				case "win" :
					${"{$league}win"} = ${"{$league}win"} + 1;
					break;
				case "loss" :
					${"{$league}loss"} = ${"{$league}loss"} + 1;
					break;
				case "tie" :
					${"{$league}tie"} = ${"{$league}tie"} + 1;
					break;
			endswitch;

			
		}
		echo ${"{$league}win"};
		echo ${"{$league}loss"};
		echo ${"{$league}tie"};
	}
} 
?>
works perfect !!!

ty..:0
Post Reply