I am trying to write a simple script to act as a sort-of captcha in a form. I know this isn't nowhere near as good as using a captcha but I wanted to do it as I'm new to PHP and it's good learning.
<?php $a = rand(1, 10); $b = rand(1, 10); $array = array( "+", "-", "/", "*" ); $operator = $array[array_rand($array)]; $answer = ; ?> What should I use to calculate $answer?
I need PHP to do $answer = $a $operator $b, for example $answer = 8 + 2 so $answer = 10.
evalcan be dangerous.$answer = eval($a . $operator . $b). Yes, i do know eval is evil, that's what everyone says, but in that case, it's completely fine.evil()) in the dupe.$answer = $a +$operator +$b; echo $answer;