在PHP中使用或不使用大括号的重要或含义是什么? [关闭]

I am just wondering if there are reasons or an advantage of writing PHP snippet with or without using curly braces.

I have these three approach of getting ordinal suffix of numbers. What should be the best approach in this case

Approach 1: Without "braces" the "curly brackets"

function ordinalSuffix($n) {
    //any number such as zero(0) should end with 'th' other than 1,2,3 which must be 1st 2nd 3nd
    $appends = array('th','st','nd','rd','th','th','th','th','th','th');
    // using php modulus check if number is 11, 12 or 13 
    if ((($n % 100) >= 11) && (($n % 100) <= 13))
        return $n. 'th'."<br/>";
    else
           return $n. $appends[$n % 10]."<br/>";
}
//Example Usage
$studentMarks=range(1,26);
foreach($studentMarks as $key => $studentResult)
//check for odd and even
if(($key % 2) == 1)
echo "<div class='dark'>Student - (". ($key + 1) .") Result is :".ordinalSuffix($studentResult)."</div>";
else 
echo "<div class='ligth'>Student - (". ($key + 1) .") Result is :".ordinalSuffix($studentResult)."</div>";

Approach 2: Without "braces" the "curly brackets"

function ordinalSuffix($n) {
    //any number such as zero(0) should end with 'th' other than 1,2,3 which must be 1st 2nd 3nd
    $appends = array('th','st','nd','rd','th','th','th','th','th','th');
    // using php modulus check if number is 11, 12 or 13 
    if ((($n % 100) >= 11) && (($n % 100) <= 13)):
        return $n. 'th'."<br/>";
    else:
           return $n. $appends[$n % 10]."<br/>";
    endif;
}
//Example Usage
$studentMarks=range(1,26);
foreach($studentMarks as $key => $studentResult):
//check for odd and even
if(($key % 2) == 1):
echo "<div class='dark'>Student - (". ($key + 1) .") Result is :".ordinalSuffix($studentResult)."</div>";
else: 
echo "<div class='ligth'>Student - (". ($key + 1) .") Result is :".ordinalSuffix($studentResult)."</div>";
endif;
endforeach; 

Approach 3: Makes use of "braces" the "curly brackets"

function ordinalSuffix($n) {
    //any number such as zero(0) should end with 'th' other than 1,2,3 which must be 1st 2nd 3nd
    $appends = array('th','st','nd','rd','th','th','th','th','th','th');
    // using php modulus check if number is 11, 12 or 13 
    if ((($n % 100) >= 11) && (($n % 100) <= 13)){
        return $n. 'th'."<br/>";
    }
    else{
           return $n. $appends[$n % 10]."<br/>";
    }
}
//Example Usage
$studentMarks=range(1,26);
foreach($studentMarks as $key => $studentResult){
//check for odd and even
if(($key % 2) == 1){
echo "<div class='dark'>Student - (". ($key + 1) .") Result is :".ordinalSuffix($studentResult)."</div>";
}
else{ 
echo "<div class='ligth'>Student - (". ($key + 1) .") Result is :".ordinalSuffix($studentResult)."</div>";
}
}

Then you never have to worry about what code is executed as part of your conditional. Don't let your future self, or whomever maintains this code, make a stupid, preventable error. All it takes is adding one extra line to your IF statement without the brace and unexpected, hard to catch, bugs occur. It's also easier to read. Maintainability is always important and should not be ignored.