缩短是否可以? [英] shorten if else, possible?

查看:70
本文介绍了缩短是否可以?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

 if(count($a) > 0){
   $a = $b;
 } else { 
   $c = $b;
 }

是否可以使用三元运算符重写它?或任何缩短它的方法?谢谢!

Is it possible to re-write this, using ternary operators? or any way to shorten it? Thanks!

推荐答案

(count($a) > 0) ? $a = $b : $c = $b;

这篇关于缩短是否可以?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆