vendredi 17 janvier 2020

Using values in one associative array to test against values in another associative array

I need help, tried for days without successs, new to PHP so please forgive me, I have an associative Array below returned from a database table grading system, what I want to achieve is try "scores" from another associative array, iterate through the grading system until I find a score that falls between values in a row in the grading system then return the letter grade and remarks, see below what have tried, am exhausted, any help would be very appreciated.

Array
(
    [0] => Array
        (
            [id] => 2
            [grade_min] => 1
            [grade_max] => 39
            [grade] => E
            [remarks] => Fail
        )

    [1] => Array
        (
            [id] => 3
            [grade_min] => 40
            [grade_max] => 49
            [grade] => D
            [remarks] => Pass
        )

    [2] => Array
        (
            [id] => 4
            [grade_min] => 50
            [grade_max] => 59
            [grade] => C
            [remarks] => Credit
        )

    [3] => Array
        (
            [id] => 5
            [grade_min] => 60
            [grade_max] => 69
            [grade] => B
            [remarks] => Good
        )

    [4] => Array
        (
            [id] => 6
            [grade_min] => 70
            [grade_max] => 79
            [grade] => A
            [remarks] => Very Good
        )

    [5] => Array
        (
            [id] => 7
            [grade_min] => 80
            [grade_max] => 100
            [grade] => A+
            [remarks] => Excellent
        )

)
Array
(
    [0] => Array
        (
            [id] => 2
            [grade_min] => 1
            [grade_max] => 39
            [grade] => E
            [remarks] => Fail
        )

    [1] => Array
        (
            [id] => 3
            [grade_min] => 40
            [grade_max] => 49
            [grade] => D
            [remarks] => Pass
        )

    [2] => Array
        (
            [id] => 4
            [grade_min] => 50
            [grade_max] => 59
            [grade] => C
            [remarks] => Credit
        )

    [3] => Array
        (
            [id] => 5
            [grade_min] => 60
            [grade_max] => 69
            [grade] => B
            [remarks] => Good
        )

    [4] => Array
        (
            [id] => 6
            [grade_min] => 70
            [grade_max] => 79
            [grade] => A
            [remarks] => Very Good
        )

    [5] => Array
        (
            [id] => 7
            [grade_min] => 80
            [grade_max] => 100
            [grade] => A+
            [remarks] => Excellent
        )

)

Scores Array looks like this
Array
(
    [0] => 35
    [1] => 48
    [2] => 57
    [3] => 78
    [4] => 75
    [5] => 89
)


I want to iterate these scores array against the grading system array and return only the "grade" and "remarks" that matched where the scores is between "grade_min" and "grade_max"

Aucun commentaire:

Enregistrer un commentaire