有这个while循环后有更好的方法来获得结果

I'm gonna put this into a database for example:

Enchant: enchant_id 1, 1 str, 6 dex.

That's why i'm looping through it.

I get the result i want, but is there a better way of doing this?

<?php
$str = 1;
$dex = 1;
while ($dex <= 7) {
    echo "Str: $str";
    echo " - ";
    echo "Dex: $dex";
    echo "<br>";
    $dex++;
    if($dex == 8) {
        echo "<br>";
        $str = 2;
        $dex = 1;
        while ($dex <= 7) {
            echo "Str: $str";
            echo " - ";
            echo "Dex: $dex";
            echo "<br>";
            $dex++;
            if($dex == 8) {
                echo "<br>";
                $str = 3;
                $dex = 1;
                while ($dex <= 7) {
                    echo "Str: $str";
                    echo " - ";
                    echo "Dex: $dex";
                    echo "<br>";
                    $dex++;
                }
            }
         }
    }
}

?>

This outputs:

Str: 1 - Dex: 1
Str: 1 - Dex: 2
Str: 1 - Dex: 3
Str: 1 - Dex: 4
Str: 1 - Dex: 5
Str: 1 - Dex: 6
Str: 1 - Dex: 7

Str: 2 - Dex: 1
Str: 2 - Dex: 2
Str: 2 - Dex: 3
Str: 2 - Dex: 4
Str: 2 - Dex: 5
Str: 2 - Dex: 6
Str: 2 - Dex: 7

Str: 3 - Dex: 1
Str: 3 - Dex: 2
Str: 3 - Dex: 3
Str: 3 - Dex: 4
Str: 3 - Dex: 5
Str: 3 - Dex: 6
Str: 3 - Dex: 7

How can i simplify the code to get the same result?

The sample output you show can be achieved with a simple nested for loop. For example:

for ($str = 1; $str <= 7; $str++) {
    for ($dex = 1; $dex <= 7; $dex++) {
        echo "Str: $str - Dex: $dex<br />";
    }
    echo "<br />"; // For the extra space between sets
}

The key here when looking at your desired output is to recognize the patterns. You have an incrementing value on the left (STR) and an incrementing value on the right (DEX). That's two loops. The pattern is such that for each single increase on the left (the outer loop) there is a full set of value on the right (the inner loop).