Minzer Posted April 28, 2021 Share Posted April 28, 2021 (edited) //$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 April 28, 2021 by Minzer solved Quote Link to comment https://forums.phpfreaks.com/topic/312562-convert-string-into-already-available-variable/ Share on other sites More sharing options...
requinix Posted April 29, 2021 Share Posted April 29, 2021 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/312562-convert-string-into-already-available-variable/#findComment-1586230 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.