如果变量中存在某个字符,则将字符附加到变量中?
我将如何进行以下 also 检查 $word 的最后一个字符是否等于“h”,如果为真,则附加“es”?对“h”的检查将在对“s”的检查之前进行,如果为真,则无需检查“s”。
<?php
$word = "watch";
$newword = "$word".(substr($word, -1)=="s"?"":"s")." is the new word";
echo $newword;
?>
How would I go about making the following also check if the last character of $word is equal to "h" if true then append "es"? This check for "h" would be before the check for "s" and if true there would be no need to check for "s".
<?php
$word = "watch";
$newword = "$word".(substr($word, -1)=="s"?"":"s")." is the new word";
echo $newword;
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
或其某种变体。如果您尝试使单词复数,已经有很多解决方案,例如: 复数方法
Or some variation thereof. If you are trying to pluralize words, there are already a number of solutions, for example: pluralize method