Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php $\u POST方法从数组中提取并显示结果_Php_Html_Arrays_Forms - Fatal编程技术网

Php $\u POST方法从数组中提取并显示结果

Php $\u POST方法从数组中提取并显示结果,php,html,arrays,forms,Php,Html,Arrays,Forms,因此,我希望表单找到用户搜索的内容,然后通过下面的数组返回搜索结果。这可能吗?我曾试图自己编写php,但我一窍不通 <form action="result.php" method="post"> <input type="text" name="country" size="30" id="autocomplete-ajax" placeholder="Search for country, timezone or city a

因此,我希望表单找到用户搜索的内容,然后通过下面的数组返回搜索结果。这可能吗?我曾试图自己编写php,但我一窍不通

            <form action="result.php" method="post">
            <input type="text" name="country" size="30" id="autocomplete-ajax" placeholder="Search for country, timezone or city and hit enter!" maxlength="30">
            </form>

                <?php
                $countries = array(   
                "AD" => "Andorra",   
                "AE" => "United Arab Emirates",   
                "AF" => "Afghanistan",
                "AG" => "Antiqua and Barbuda",
                "AI" => "Anguilla",
                "AL" => "Albania",          
                "ZZ" => "Unkown or Invalid Region");

                if (isset($_POST[$countries[0]])){
                echo "<p>Correct!</p>";
                }
                if (isset($_POST[$countries[1]])){
                echo "<p>Correct2</p>";
                }
                ?>

您可以用此替换其他ISSET-它将根据数组检查post值
如果(isset($_POST[“country”])){
foreach($k=>c的国家){
如果(strtolower($c)==strtolower(trim($_POST[“country”])){
回声“正确!

”; } } }
我也有自动完成js,我只希望输入与用户搜索的php数组相匹配。
You could replace the other issets with this - it will check the post values against the array 

   if (isset($_POST["country"])){
        foreach($countries as $k => $c){
            if(strtolower($c) == strtolower(trim($_POST["country"]))){
                 echo "<p>Correct!</p>";
            }
        }
    }