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

  • Home
  • SEARCH
  • 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 3958462
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:36:45+00:00 2026-05-20T02:36:45+00:00

I have a CSV of GDP figures, both nominal and PPP. The structure is

  • 0

I have a CSV of GDP figures, both nominal and PPP. The structure is Country,Nominal,PPP.

Example:

Islamic Republic of Afghanistan,560.673,998.466
Albania,"3,616.10","7,381.00"
Algeria,"4,477.80","7,103.61"

Users enter in a nominal GDP value. What I’m trying to figure out is how to use that value to find the nearest nominal GDP value in an array constructed from the CSV file. Once I find the nominal value, I’m wanting to print the country and the PPP value.

I haven’t scripted anything in quite some time, so I can’t get my head around how to go about doing this.

  • 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-05-20T02:36:46+00:00Added an answer on May 20, 2026 at 2:36 am
    // $input_gdp is entered by user
    // $my_data is an array from the csv
    $closest = -1;
    $closest_diff = false;
    foreach($my_data as $key=>$row) {
        // $row[0] - Country
        // $row[1] - Nominal
        // $row[2] - PPP
        if($closest_diff === false) {
            $closest = $key;
            $closest_diff = abs($row[1] - $input_gdp); 
        } else {
            $current_diff = abs($row[1] - $input_gdp);
            if($current_diff < $closest_diff) {
                $closest = $key;
                $closest_diff = $current_diff;
            }
        }
    }
    if($closest > -1) {
        echo 'The closest is ' . $my_data[$closest][0] . ' with a PPP of ' . $my_data[$closest][2] . '.';
    } else {
        echo 'None were found.';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CSV file in the following format: id,code,date,address,complete_url Example data from the
I have csv file with following structure: A BA0011 U206 NAME 0000000000000149.00 000000.00 0000000000000118.93
I have a csv file. The structure of the csv file is: Name Hour
I have csv input file, lets call it heights.csv . my example file has
I have CSV text thats stored in the session array as csv. The lines
I have CSV file and Macro in VBA. I want to open CSV file
I have CSV files that have multiple columns that are sorted. For instance, I
i have csv files, java app and database, i read csv file from my
I have .csv file that contain 2 columns delimited with , . file.csv word1,word2
Little Background: I have csv file which has lots of rows and each row

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.