輸入我有這樣的代碼:檢查是否陣列是相同的,從textarea的
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Frans</title>
</head>
<body>
<form method="POST">
<textarea name="textarea" cols="16" rows="4" wrap="OFF"/>
</textarea><input type="submit" name="submit" value="submit">
</form><pre><?php
if(isset($_POST['submit'])){
if(!empty($_POST['textarea'])) {
$exp = array_filter(explode("\n", $_POST['textarea']));
print_r($exp);
// Add DB Insert here
}
$correct = array(
'Beau',
'Haut',
'Jeune',
'Gros',
'Nouveau',
'Bon',
'Long',
'Vieux',
'Mauvais',
'Autre',
'Joli',
'Petit',
'Grand',
'Large',
'Premier',
'Cher',
);
$input = $_POST['textarea'];
echo ($correct == $input) ? 'they\'re same' : 'they\'re different';
print_r($correct);
}
?>
</body>
</html>
我basicly要檢查,如果該陣列是相同的,從textarea的輸入。這是輸入應該是什麼:
雪兒 博 浩 熱恩 格羅斯 風格 苯教 龍 老 MAUVAIS 其它物業 阿邦 佩蒂特 大 大 總理
輸出結果應該是:重新相同。 但我做錯了,因爲它一直說:「他們不同」 在此先感謝。
輸入錯了,請原諒。 編輯:
博 浩 熱恩 格羅斯 風格 苯教 龍 老 MAUVAIS 其它物業 阿邦 佩蒂特 大 大 總理 雪兒
參見http://stackoverflow.com/questions/901815/php-compare-array – aland 2014-10-29 20:19:40
'$輸入= $ _POST [ 'textarea的']'是一個字符串,而不是陣列。我想你想比較'$ correct'和'$ exp'來代替。 – showdev 2014-10-29 20:20:21