整数 (1 または 0) を出力すると、すべての反復 (この場合は 3 つ) で正しい数値が出力されます。最初と 2 番目のものは 1 を返し、最後のものは 0 を返します。しかし、「if」ステートメントはとにかくすべてを表示しているようです。私は何を間違っていますか?
以下のすべてのコードは、より大きな「for」ループ内にあります。
$yn = 0;
if(!in_array($pos, $blocks)){
$blocks[$x] = $pos;
$x++;
$yn = 1;
}
print_r($blocks);
print "YN: ".$yn; # this prints out 1, 1 and 0 on the last iteration
if(yn){
# show some stuff (is displayed in all three iterations, but it shouldn't be on the last)
}