How can nested if-else statements be used effectively in PHP to assign values based on multiple criteria?
Nested if-else statements can be used effectively in PHP to assign values based on multiple criteria by checking multiple conditions in a hierarchical manner. This allows for more complex decision-making processes where different outcomes are determined based on various combinations of conditions.
$score = 85;
$grade = '';
if ($score >= 90) {
$grade = 'A';
} else {
if ($score >= 80) {
$grade = 'B';
} else {
if ($score >= 70) {
$grade = 'C';
} else {
$grade = 'D';
}
}
}
echo "Grade: " . $grade;