<!DOCTYPE html>
<html lang="ru">
<head>
<title>Функция выборки option</title>
<meta charset='utf-8'>
</head>
<body>
<form action="<?=$_SERVER('addOption.php')?>" method="POST">
<?php require_once 'addOption.php';?>
<?=echo test();?>
<select name="surname">
<?php require_once 'addOption.php'; ?>
<?= SelectItem(Snames, $_REQUEST['surname']); ?>
</select><br/>
<input type="submit" value="Узнать фамилию">
</form>
</body>
</html>
<?php
$names = [
"Weaving" => "Hugo",
"Goddard" => "Paul",
"Taylor" => "Robert",
];
if (isset($_REQUEST['surname'])) {
$name = $names[$_REQUEST['surname']];
echo "Вы выбрали: ".$_REQUEST ['surname'] .',' .$name;
function test(){
return 'test';
}
function SelectItem($items,$selected = 0){
$text = "";
foreach($items as $k => $v){
if($k === $selected) $ch = ' selected';
else $ch = '';
$text .= "<option$ch value='$k'>$v</option>\n";
}
return $text;
}
?>