0

我是新来的!

使用$_POST,PHP 接受三个数字,只打印偶数且需要排序的数字。我很讨厌这个,但我试过这是我的代码:

<body>

<form name="getallen" action="111.php" form method="POST">
Geef drie getallen in.</br>
Getallen: 
<input type="text" name="getallen" maxlength=""/></br>
<input type="text" name="getallen" maxlength=""/></br>
<input type="text" name="getallen" maxlength=""/></br>
<input type="submit" value="controle"/>
</form>

</body>


<?php


$_POST ["getallen"];


if (is_array($_POST['getallen'])) { 
echo 'Resultaat: <br />'; 
foreach ($_POST['getallen'] as $r) {
sort($_POST['getallen']); 
echo "<i>$r</i><br />";
} 
}else {
    echo "Gelieve juiste getallen in te geven";
    }


?> 
4

2 回答 2

1

您的输入表单应该是数组

<input type="text" name="getallen[]" value="" /><br />
<input type="text" name="getallen[]" value="" /><br />
<input type="text" name="getallen[]" value="" /><br />

现在试试 print_r($_POST); 或者你可以循环使用

foreach ( $_POST as $r ) {
    echo $r.'<br />';
}
于 2013-05-23T18:55:10.617 回答
0

There is a lot wrong with your code. I would recommend brushing up on the basics of PHP and HTML forms, but you probably want something like this:

HTML:

<input type="text" name="getallen[]" /><br />
<input type="text" name="getallen[]" /><br />
<input type="text" name="getallen[]" /><br />

PHP:

$sortedArray = sort($_POST['getallen']);
foreach($sortedArray as $r){
  if(($r % 2) == 0){
    echo "<i>$r</i><br />";
  }
  else{
    echo "Gelieve juiste getallen in te geven";
  }
}
于 2013-05-23T19:02:34.797 回答