I want to assign values from an array to a simple variable, my code is as follows :
$codeval = $_POST['code']; //can be Apple or Banana or Cat or Dog
$systemrefcode = array("a" => "Apple", "b" => "Banana", "C" => "Cat", "D" => "Dog");
foreach($systemrefcode as $code => $value) {
if($codeval == $value){ //if Apple exists in array then assign code and use it further
$codes = $code;//Assign code to codes to use in next step
}
$selection = 'Your Selection is -'.$codes.'and its good.';
echo $selection;
When I check in console it shows no response. What am I doing wrong?
"D => "Dog". Try"D" => "Dog"and there is a closing}missing.