Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9147149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:55:04+00:00 2026-06-17T10:55:04+00:00

Trying to create a GPA Calculator. I have a form that submits to a

  • 0

Trying to create a GPA Calculator. I have a form that submits to a php file and then stores all data from the form in a php array(). The calculator works great until I enter the same value. I think this wont make sense until I show some pictures:

Here is the problem in an image:

Error Scenario

Correct Scenario

So in the first image I enter a A and then another A which outputs array(1) { [0]=> float(4.5) } when using var_dump()

And in the second image the var_dump() is array(2) { [0]=> float(4) 1=> float(3.5) }

It is skipping the first row in the first image… just in case A is supposed to equal 4.0 in REG and 4.5 in HONORS. It might be the array_combine()

Here is my php code:

//$_POST['grades'] for the grades <option> and $_POST['types'] for the type (REG, HONORS)
foreach(array_combine($_POST['grades'], $_POST['types']) as $code => $count)
{

    if ($code == "A")
    {
        if ($count == "REGULAR")
        {
            $GradeArray[] = 4.0;
        }
        else if ($count == "HONORS")
        {
            $GradeArray[] = 4.5;
        }
        else if ($count == "COLLEGE")
        {
            $GradeArray[] = 5.0;
        }
    }
    else if ($code == "B")
    {
        if ($count == "REGULAR")
        {
            $GradeArray[] = 3.0;
        }
        else if ($count == "HONORS")
        {
            $GradeArray[] = 3.5;
        }
        else if ($count == "COLLEGE")
        {
            $GradeArray[] = 4.0;
        }
    }
    else if ($code == "C")
    {
        if ($count == "REGULAR")
        {
            $GradeArray[] = 2.0;
        }
        else if ($count == "HONORS")
        {
            $GradeArray[] = 2.5;
        }
        else if ($count == "COLLEGE")
        {
            $GradeArray[] = 3.0;
        }
    }
    else if ($code == "D")
    {
        if ($count == "REGULAR")
        {
            $GradeArray[] = 1.0;
        }
        else if ($count == "HONORS")
        {
            $GradeArray[] = 1.5;
        }
        else if ($count == "COLLEGE")
        {
            $GradeArray[] = 2.0;
        }
    }
    else if ($code == "F")
    {
        if ($count == "REGULAR")
        {
            $GradeArray[] = 0.0;
        }
        else if ($count == "HONORS")
        {
            $GradeArray[] = .5;
        }
        else if ($count == "COLLEGE")
        {
            $GradeArray[] = 1.0;
        }
    }


}

It might be the whole foreach() statement that needs reworking… I am up to writing the logic again if anyone says so…

I don’t want to clog up the question with code so if you absolutely need the html just ask and I will add in an edit.

EDIT: I am also thinking I need to rewrite the logic… I have never used array_combine() before… I just need to make sure the corresponds with the related

Thanks for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:55:05+00:00Added an answer on June 17, 2026 at 10:55 am

    look at this array and output look the VALUES “a” which becomes the key of the resultant array,
    so if u want the full array to be combined with the key of first array then first array must kave unique values.

      <?php
        print_r(array_combine(Array('a','a','b'), Array(1,2,3)));
        ?>
        Returns:
        Array
        (
            [a] => 2
            [b] => 3
        )
    

    solution (may not be the best )

    foreach($_POST['grades'] as $KEY=>$code)
    {
       $count  = $_POST['types'][$KEY];
       if ($code == "A")
        {
            if ($count == "REGULAR")
            {
                $GradeArray[] = 4.0;
            }
            else if ($count == "HONORS")
            {
                $GradeArray[] = 4.5;
            }
            else if ($count == "COLLEGE")
            {
                $GradeArray[] = 5.0;
            }
        }
        else if ($code == "B")
        {
            if ($count == "REGULAR")
            {
                $GradeArray[] = 3.0;
            }
            else if ($count == "HONORS")
            {
                $GradeArray[] = 3.5;
            }
            else if ($count == "COLLEGE")
            {
                $GradeArray[] = 4.0;
            }
        }
        else if ($code == "C")
        {
            if ($count == "REGULAR")
            {
                $GradeArray[] = 2.0;
            }
            else if ($count == "HONORS")
            {
                $GradeArray[] = 2.5;
            }
            else if ($count == "COLLEGE")
            {
                $GradeArray[] = 3.0;
            }
        }
        else if ($code == "D")
        {
            if ($count == "REGULAR")
            {
                $GradeArray[] = 1.0;
            }
            else if ($count == "HONORS")
            {
                $GradeArray[] = 1.5;
            }
            else if ($count == "COLLEGE")
            {
                $GradeArray[] = 2.0;
            }
        }
        else if ($code == "F")
        {
            if ($count == "REGULAR")
            {
                $GradeArray[] = 0.0;
            }
            else if ($count == "HONORS")
            {
                $GradeArray[] = .5;
            }
            else if ($count == "COLLEGE")
            {
                $GradeArray[] = 1.0;
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to develop a basic GPA Calculator. I have an AllCourses class that
I am trying create system in which I can login from php and then
I am trying create a data.frame from which to create a graph. I have
I'm trying create an immutable object and initialise it from xml config file in
I am trying create a WCF Data Services ServiceOperation that does grouping on the
I'm trying create new object from a module class in VBA, and I have
I'm trying create simple application in C++. This application has to read from file
I'm trying create a method that returns the sum of all values in an
Trying to create Database as follows: USE Master GO IF NOT EXISTS(SELECT [Name] FROM
I'm trying create grammar for SRT format: Here is an example of srt file:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.