如何使用数组以防万一? [英] How to use an array in case?
本文介绍了如何使用数组以防万一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在切换的情况下如何使用数组?这不起作用,并且始终采用默认值(3):
How can I use an array in the case of a switch? This doesn't work and always take the default (3):
switch ($my_array) {
case array('george','paul'):
$id = 1;
break;
case array('paul','max'):
$id = 2;
break;
case array('eric'):
$id = 3;
break;
//default
default:
$id = 3;
break;
}
推荐答案
$a == $b
:如果$ a和$ b具有相同的键/值对,则为TRUE.
$a == $b
: TRUE if $a and $b have the same key/value pairs.
由于 switch/case 使用弱比较,因此使用==
运算符比较数组.
Since switch/case uses weak comparison, arrays are compared by using the ==
operator.
我已将一个有效的示例放到了键盘上: http://codepad.org/MhkGpPRp
I've put a working example onto codepad: http://codepad.org/MhkGpPRp
这篇关于如何使用数组以防万一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文