试图在将其添加到Production之前测试我的代码,但为什么foreach循环仅将3个值传递给$strokes
而不是所有4 $_POST
数组值。其中之一是0
。为什么通过foreach循环的值不是0?
$_POST = array("h1" => 1, "h2" => 2, "h3" => 3, "h4" => 0);
$strokes = array();
$strokes_keys = array('h1', 'h2', 'h3', 'h4');
foreach ($strokes_keys as $stroke) {
if ($_POST[$stroke]) {
array_push($strokes, $_POST[$stroke]);
}
}
$counts = count($strokes);
var_dump($strokes);
var_dump($counts);
结果:
Success time: 0.04 memory: 52480 signal:0
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
int(3)
尝试:if($ _POST [$ stroke]!== null) –
为什么要将数组命名为$ _POST?为什么??? – khandelwaldeval
@khandelwaldeval我只是复制客户端'POST'。 – Conor