juniorek9 Posted April 25, 2012 Share Posted April 25, 2012 Hi Guys. I need some hep with a small math thing regarding the math. I`m trying to make the php code so it generates math questions and check the answers. i got the part with asking questions working but how do i get the php to work out the correct answer and compare with the posted answer? My bit of a code to work the questions is bellow 18195_.txt Quote Link to comment https://forums.phpfreaks.com/topic/261606-math-test/ Share on other sites More sharing options...
silkfire Posted April 26, 2012 Share Posted April 26, 2012 If the math answers are simple operand type, you can use eval but you might need some replacements done first. $answer = '4 x 5'; $answer = str_replace('x', '*', $answer); eval('$answer = ' . $answer . ';'); But be careful eval is discouraged but I don't know the alternative. Quote Link to comment https://forums.phpfreaks.com/topic/261606-math-test/#findComment-1340734 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.