if($type==0)
$type_value="a";
if($type==1)
$type_value="b";
if($type==2)
$type_value="c";
看看可以精简到什么程度。主要是为了得到$type_value的值,可以增加第三或第四个变量
我的做法如下:
$arr=array('a','b','c');
$type_valu=$arr[$type];
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
方法一:高逼格,$type_value=$type==0?'a':($type==1?'b':($type==2&&'c'))
方法二:用ascii码,$type_value=chr($type+97);
不用谢,请叫我红领巾
类似的php写法请自行YY
另外,你的那种想法其实
"abc"[$type]
就行了。前提: