需要检查 $message 长度是否为 7 个字符或更少,如果是,则执行操作 A,如果不是,则执行操作 B。这是正确的语法吗?我认为我做错了什么?
<?php
if (strlen($message) <= 7) {
echo $actiona;
} else {
echo $actionb;
}
?>
最佳答案
没关系。例如,让我们运行以下命令:
<?php
$message = "Hello there!";
if (strlen($message) <= 7){
echo "It is less than or equal to 7 characters.";
}
else
{
echo "It is greater than 7 characters.";
}
?>
它将打印:“它大于 7 个字符。”
关于php 检查变量长度是否等于一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1141629/