Jump to content

Convert string into already available variable ?


Recommended Posts

//$value1 = $_POST['game'];

$value1 = "game7h";

if (strpos($value1, 'a')) {
$team = 'a';
}elseif (strpos($value1, 'h')) {
$team = 'h';
}      
if (strpos($value1, '7')) {
$num = '7';
} elseif (strpos($value1, '8')) {
$num = '8';
} elseif (strpos($value1, '9')) {
$num = '9';
}

$gm7hodds = $games[41]["BP"];
$gm7aodds = $games[40]["BP"];

$gm8hodds = $games[47]["BP"];
$gm8aodds = $games[46]["BP"];

$gm9hodds = $games[53]["BP"];
$gm9aodds = $games[52]["BP"];


/* 
$getratio = $num + $team;

echo $getratio;

Team is not a math operation so I'll finesse that later.

*/


$findratio = 'gm' . $num . 'h' . 'odds';
echo $findratio;

gm7hodds

How would I add the $ to it and return its array value $gm7hodds?

Solved whoops ->

echo eval('return $'. $findratio. ';');

Edited by Minzer
solved
Link to post
Share on other sites
  • Minzer changed the title to Convert string into already available variable ?

No. Using eval is a really bad idea. There are always better solutions to problems than using eval.

$num is the only unknown part, right? Look at this:

$gm = array(
	9 => array(
		"hodds" => $games[53]["BP"],
		"aodds" => $games[52]["BP"]
	)
);

echo $gm[$num]["hodds"];

Really easy.

  • Haha 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.