1

我有以下数据结构;

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。

任何人都可以提出更好的方法吗?

4

2 回答 2

0

也许尝试使用 in_array() 方法

php.net in_array()

于 2013-10-17T12:01:43.197 回答
0

尝试使用这样的引用:

$rank0 =& $hand[0]['rank'];
$rank1 =& $hand[1]['rank'];

if (
($rank0 == "A" && $rank1 == "A")
|| (...)

只是,作为代码最小化的第一步

于 2013-10-17T12:07:50.630 回答