1
我想检查comment
数组的字符串长度。 一旦他们中的任何一个等于或高于4,我想回显相关的值,然后停止。“break”不能正常工作
我猜想使用while
应该是好的, 但如果我打破在4
或更多的循环,没有什么会得到回应。 如果我打破它5
或更多,前面的两个4字符串值将被回显,但我只需要第一个4字符串值回显,然后停止。
$comment[1] = "abc"; // add comment below text button
$comment[2] = "xyz"; // add comment below text button
$comment[3] = "abcd"; // add comment below text button
$comment[4] = "xyza"; // add comment below text button
$comment[5] = "abcde"; // add comment below text button
$comment[6] = "xyzab"; // add comment below text button
$x = 1;
while ($x <= 10) {
if (strlen((string)$comment[$x]) >= 4) {
echo $comment[$x];
echo "<br/>";
}
$x = $x + 1;
if (strlen((string)$comment[$x]) >= 4) break; // Nothing get echoed
// if (strlen((string)$comment[$x]) >= 5) break; // two values get echoed
}
此外,有没有可能是更好/更短的做法来检查这个东西,也许有些内置函数一样in_array
?