this is where I am declaring array of operators for generating an expressions
// Read operations from the POST params and map the array that looks like fo my purpose
// ['Addition', 'Multiplication'] as ['+', '*']
$operations_map = array(
'Addition' => '+',
'Subtraction' => '-',
'Multiplication' => '*',
'Division' => '/',
);
$operations = array_map(function($operation_name) use ($operations_map){
return $operations_map[$operation_name];
}, $_POST['operation'] ?? []);
// generate expressions using the specified random seed
srand($seed);
$expressions = array();
for ($i = 1; $i <= $num_questions; $i++) {
$expression = generate_expression($num_operands, $operations, $num_digits);
$expression_string = implode(" ", $expression);
$result = eval("return ($expression_string);");
$expressions[] = compact("expression", "result");
}
return compact(
'play',
'seed',
'num_digits',
'num_questions',
'num_operands',
'operations',
'expressions',
'duration'
);
}
here I wanat to display x
as a multiplication sign and perform the operation instead of using *
sign , I have tried many ways like replacing it directly with x , by using ×
also but eval function is showing error every time I am rrequesting output through my form
The rest of the code is working perfectly but with *
symbol ,
what should I do ?