【发布时间】:2017-10-21 16:14:34
【问题描述】:
我建立了一个表格,要求你用德语写一个单词,它会告诉你应该使用哪个定冠词。
我使用了三个问题的数组:
- Cross check if multiple variable are equal in php
- Check if two arrays have the same values
- PHP - Check if two arrays are equal
这是我的代码:
<form action="index.php" method="post">
<input type="text" class="form-control" id="word" name="word" placeholder="Word">
<button type="submit" class="btn btn-secondary">See</button>
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
$word = $_POST["word"];
$das = ["Kind", "Licht", "Mädchen"];
$der = ["Hund", "Kater", "Mann", "Storm", "Winter"];
$die = ["Dame", "Frau", "Katze"];
sort($word);
sort($das);
sort($der);
sort($die);
if ($word == $das)
{
echo "It is a <b>das</b>.";
}
elseif ($word == $der)
{
echo "It is a <b>der</b>.";
}
else
{
echo "It is a <b>die</b>.";
}
}
?>
【问题讨论】:
-
了解
in_array()- php.net/manual/en/function.in-array.php -
问题在哪里?期望什么?为什么
sort($word)?sort()用于数组 (php.net/manual/en/function.sort.php)。请改进问题 -
@mloureiro,因为
sort忽略了大小写相同单词之间不区分大小写的差异。