PHP 打印九宫格逻辑方法

function index()
{
    for($b=1; $b<=9; $b++){

        for($e=1; $e<=9; $e++){

            for($h=1; $h<=9; $h++){

                if($b+$e+$h=='15' && $b!=$e && $h!=$e){

                    for($d=1; $d<=9; $d++){

                        for($f=1; $f<=9; $f++){

                            if($d+$e+$f == '15' && $d%2!=0 && $f%2!=0 && $d!=$e && $f!=$e){

                                for($a=1; $a<=9; $a++){

                                    for($c=1; $c<=9; $c++){

                                        for($g=1; $g<=9; $g++){

                                            for($i=1; $i<=9; $i++){

                                                if($a+$b+$c == '15' && $a+$d+$g== '15' && $a+$e+$i == '15' && $c+$e+$g == '15' && $c+$f+$i == '15' && $g+$h+$i == '15' && $a%2==0 && $c%2==0 && $g%2==0 && $i%2==0){

                                                    echo $a.'-'.$b.'-'.$c.'<br/>';
                                                    echo $d.'-'.$e.'-'.$f.'<br/>';
                                                    echo $g.'-'.$h.'-'.$i.'<br/>';
                                                    echo '<br/>';
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

index();

猜你喜欢

转载自blog.csdn.net/qq_24909089/article/details/79852697