尝试通过给定输入回显条件,但结果是三次我想通过给定输入的单个结果条件

**hi here is the code please answer my question. I'm trying to echo condition by given input but results are three times I want single result condition by given input **

<?php
$arrayName = array('bravo', 'alpha', 'jhony');

foreach ($arrayName as $key) {
    if (isset($_REQUEST['num1']) && $_REQUEST['num1'] == $key) {
        echo "yes". $_REQUEST['num1']. "Available";
    } else {
        echo "Sorry!".$_REQUEST['num1']." is not available";
    }
}
?>


<form action="" method="get" accept-charset="utf-8">
<input type="text" name="num1">
<button type="submit">submit</button></form>

Rather than loop through your white list, use in_array:

$arrayName = array('bravo','alpha','jhony' );


if(isset($_REQUEST['num1']) && in_array($_REQUEST['num1'], $key)){
 echo "yes". $_REQUEST['num1']. "Available";
}
else{
    echo "Sorry!".$_REQUEST['num1']." is not available";
}