我有以下数据结构;
Array ( [0] => Array ([suit] => c [rank] => A )
[1] => Array ( [suit] => d [rank] => A ) )
我想测试这些卡是否是特定值并显示相应的消息;
if (
(($hand[0]['rank'] == "A") && ($hand[1]['rank'] == "A"))
|| (($hand[0]['rank'] == "K") && ($hand[1]['rank'] == "K"))
|| (($hand[0]['rank'] == "Q") && ($hand[1]['rank'] == "Q"))
|| (($hand[0]['rank'] == "A") && ($hand[1]['rank'] == "K"))
|| (($hand[0]['rank'] == "K") && ($hand[1]['rank'] == "A"))
) {
echo "Action: Raise pre-flop. Re-raise if already raised.<br />\n";
}
if (
(($hand[0]['rank'] == "7") && ($hand[1]['rank'] == "7"))
|| (($hand[0]['rank'] == "A") && ($hand[1]['rank'] == "J") && ($hand[0]['suit'] == $hand[1]['suit']))
|| (($hand[0]['rank'] == "J") && ($hand[1]['rank'] == "Q") && ($hand[0]['suit'] == $hand[1]['suit']))
|| (($hand[0]['rank'] == "10") && ($hand[1]['rank'] == "J") && ($hand[0]['suit'] == $hand[1]['suit']))
) {
echo "Action: Worth a call pre-flop (provided no-one has raised).<br />\n";
}
我通过删除一些条件简化了IF。
有人能建议更好的方法吗?
答案 0 :(得分:0)
也许尝试使用in_array()方法
答案 1 :(得分:0)
尝试使用这样的引用:
$rank0 =& $hand[0]['rank'];
$rank1 =& $hand[1]['rank'];
if (
($rank0 == "A" && $rank1 == "A")
|| (...)
只是,作为编码最小化的第一步