如何检查唯一的值?
我有一个带有随机变量名的开关和一个可以包含左、右、上、下值的数组。
例如:
switch ($i) {
case 0:
$name='something1';
$array=array('north', 'south', 'west');
break;
case 1:
$name='something2';
$array=array('north', 'south');
case 2:
$name='something3';
$array=array('south');
}
如何制作一个脚本来检查数组中的唯一值是否为“南”?在我的脚本中,输出将是 some3,如果我检查值的北和南,脚本将输出 some2?
希望你能理解我。谢谢!
I have an switch with a random variable name and a array which can contain the values left, right, up and down.
For example:
switch ($i) {
case 0:
$name='something1';
$array=array('north', 'south', 'west');
break;
case 1:
$name='something2';
$array=array('north', 'south');
case 2:
$name='something3';
$array=array('south');
}
How can I make a script that checks for example if the only value in the array is 'south'? In my script the output will be something3, and if I check for the value's north and south, the script would output something2?
Hope you understand me. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会这样做:
这仅在数组只有一个元素时才有效。
好吧,我认为这是实现这一目标的一种非常简单的方法:
I would do:
This will only work if the array has one element.
Ok, I think this is a pretty foolproof way of accomplishing this:
您可以直接在 PHP 中比较数组。但要小心,因为这也会比较值的顺序。
如果你能保证相同的顺序,你可以这样做:
http://codepad.viper-7。 com/TCoiDw
You can compare arrays directly in PHP. Be careful though, because this also compares the order of the values.
If you can guarantee the same order, you could do something like this:
http://codepad.viper-7.com/TCoiDw
如果我正确理解你在寻找什么,这应该可行
This should work if I understand what your looking for correctly
我认为更简单的解决方案是:
I think an easier solution would be: