gpt4 book ai didi

php - 代码替换

转载 作者:可可西里 更新时间:2023-11-01 00:36:06 26 4
gpt4 key购买 nike

我可以更换吗

if(!$mail->Send()) {
return false;
} else {
return true;
}

用这个?

return (bool)$mail->Send();

不管 $mail->Send() 返回什么(它是一个三方对象)
是否有 (bool) 与感叹号不同的类型?

最佳答案

是的,typecasting允许使用以下类型:

The casts allowed are:

  • (int), (integer) - cast to integer
  • (bool), (boolean) - cast to boolean
  • (float), (double), (real) - cast to float
  • (string) - cast to string
  • (array) - cast to array
  • (object) - cast to object
  • (unset) - cast to NULL (PHP 5)

否则,也可以使用

return !!$mail->Send();

但是,对于将来查看您的代码的其他人来说,这不是很明显。

关于php - 代码替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7244934/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com