Convert Point to Score in Php

Let's show two different methods for converting in php.

Method 1: Finding the result with if else

<?php
    $point=80; 
	$score = "No";
    if($point>=85 && $point<=100){
        $score = 5;
    } else if($point>=70 && $point<85){
        $score = 4;
    } else if($point>=60 && $point<70){
        $score = 3;
    } else if($point>=50 && $point<60){
        $score = 2;
    } else if($point>=0 && $point<50){
        $score = 1;
    }
	echo $score;
?>

Method 2: Getting the result using switch

<?php
    $point=60; 
	switch ($point) {
		case $point>=0 && $point<50:
			$score = 1;
			break;
		case $point>=50 && $point<60:
			$score = 2;
			break;
		case $point>=60 && $point<70:
			$score = 3;
			break;
		case $point>=70 && $point<85:
			$score = 4;
			break;
		case $point>=85 && $point<=100:
			$score = 5;
			break;
		default: $score = "No";
	}
	echo $score;
?>

 

Tagged In:

Software developer

26 Total Posts