<?php $operations = [ '+' => "add", '-' => "subtract" ]; // The numbers $n1 = 6; $n2 = 3; // Your operation $op = "+"; switch($operations[$op]) { case "add": // add the nos echo $n1 + $n2; break; case "subtract": // subtract the nos echo $n1 - $n2; break; default: // we can't handle other operators throw new RuntimeException(); break; }
You have javascript disabled. You will not be able to edit any code.