PHP 减法
我必须从另一个数字中减去一个数字,但脚本必须验证这是否可以在不给出负数的情况下进行。
例如,客户的信用额为 5.00 美元。他们想要购买 20 美元,但现在还缺 15 美元,因此无法购买。现在它必须将它们重定向到一个页面(资金不足)。
I have to subtract a number from another number, but the script must verify that this is possible without giving a negative number.
For example, the client's credit is $5.00. They want to make a purchase of $20, now they are short by $15 so they cannot make the purchase. Now it must redirect them to a page (Insuffient funds).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
编辑:这个问题表明您还没有充分了解基础知识。你应该去阅读有关流程结构和条件等的内容,如果你这样做的话,这样的事情会变得容易得多。
EDIT: This question screams that you've not sufficiently learned the basics. You should go read about flow constructs and conditionals and such, things like this will become much much easier if you do.
这是一个基本条件,
This is a basic conditional,
另一个解决方案是使用一个函数来检查购买是否有效(关于信用值),如下所示:
然后在您的主应用程序中执行每个人建议的操作:
祝您有美好的一天!
Another solution would be to use a function that checks if a purchase is valid, in regards to the credit value, like so:
And then in you main application do something like everyone suggested:
Have a great day!