$links = array('https://google.com', 'http://aloe.com', 'http://foobar.org/image.jpg');
foreach ($links as $link)
{
$unacceptables = array('https:','.doc','.pdf', '.jpg', '.jpeg', '.gif', '.bmp', '.png');
foreach ($unacceptables as $unacceptable)
{
if (strpos($link, $unacceptable) !== false)
{
echo 'not acceptable!<br />';
}
else
{
echo 'acceptable<br />';
}
}
}
上記出力すべき:この単純なPHP式はなぜ機能しないのですか?
not acceptable
acceptable
not acceptable
しかし、その代わりに出力する場合は、この混乱:それは右の仕事を得るための方法
not acceptable!
acceptable
acceptable
acceptable
acceptable
acceptable
acceptable
acceptable
acceptable
acceptable
acceptable
acceptable
acceptable
acceptable
acceptable
acceptable
acceptable
acceptable
acceptable
not acceptable!
acceptable
acceptable
acceptable
acceptable
?
あなたの場合は、他の*すべての*ごと* '$のunacceptable' *のために実行されています'$ link'です。 – BoltClock
3つのリンクがあり、最初のforeachは3回実行されます。受け入れられないものが8つあり、2回目のforeachは8回実行されます。すべての実行で内部ループエコーが「許容」または「許容されない」。 3 * 8 = 24行の出力。 –