# How Can i Make a Conditon to get two diffrent Percentage

i have examination result script now i am in trouble plz solve my problem "i have one database and full examination result 9th & 10th Class so 9th total marks 525 and 10th total marks 1050, now when i want to get % of 9th class its divide with 525 and when i want to get 10th class i must divide it to 1050, 9th class roll number start from 1 to 6702 and 7101 to 7152 and 20001 to 103090 rest of roll number are 10th class roll number " So plz tell me how can i make the if condition logic to get accurate % of my result or any other option or solution plz tell me regards

Try to rephrase your problem. This makes no sense.

Not sure if this helps but this is what I get from your question.

``````<?php
\$testnumbers = array("5240","7000","7142","11000","21050");

//Test Single Number
//\$roll_number = "5240";

\$ninth_roll_numbers = array();
foreach(range(1,6702) as \$num){
\$ninth_roll_numbers[] = \$num;
}
foreach(range(7101,7152) as \$num){
\$ninth_roll_numbers[] = \$num;
}
foreach(range(20001,103090) as \$num){
\$ninth_roll_numbers[] = \$num;
}

//run a little test with array \$testnumbers
foreach (\$testnumbers as \$roll_number){

\$total_marks = (in_array(\$roll_number,\$ninth_roll_numbers) ? 525 : 1050);

echo "Total Marks: \$total_marks<br />";

\$percent = \$roll_number/\$total_marks;

echo "Result: \$percent<br /><br />";

}

?>
``````

This comes out as

Total Marks: 525
Result: 9.9809523809524

Total Marks: 1050
Result: 6.6666666666667

Total Marks: 525
Result: 13.60380952381

Total Marks: 1050
Result: 10.47619047619

Total Marks: 525
Result: 40.095238095238

Could also do it with a bunch of IF greater than && less than statements but I like working with arrays.

``````echo "TEST Two<br />";

\$testnumbers = array("5240","7000","7142","11000","21050");

//run a little test with array \$testnumbers
foreach (\$testnumbers as \$roll_number){

if (
(\$roll_number>=1 && \$roll_number<=6702) ||
(\$roll_number>=7101 && \$roll_number<=7152) ||
(\$roll_number>=20001 && \$roll_number<=103090)
){
\$total_marks = 525;
}else{
\$total_marks = 1050;
}

echo "Total Marks: \$total_marks<br />";

\$percent = \$roll_number/\$total_marks;

echo "Result: \$percent<br /><br />";

}
``````

Results are the same.