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 8285825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:33:39+00:00 2026-06-08T11:33:39+00:00

I have a script that is importing data from a csv source. Many of

  • 0

I have a script that is importing data from a csv source. Many of the fields/columns are in “code.” For example, the school field is a numeric number apposed to the actual school name. I need to convert the code into the actual name before it imports into the db.

My question is, is there a quicker way to do this conversion other than using a “if” statement. Some of the fields that need to be converted have 20+ options so i am wondering if there is another way to write the conversion instead of having 20 if statments. Right now I have:

if($data['school'] = 0001) {$school = "school1"; } 
if($data['school'] = 0002) {$school = "school2"; }
if($data['school'] = 0003) {$school = "school3"; }...

or i could use if else statements

So my question is: Is there a quicker way either through some sort of array or loop or other type of php statement that I could speed up this process?

  • 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-08T11:33:41+00:00Added an answer on June 8, 2026 at 11:33 am

    Do you have all of this in a file, or do you have to type it into PHP code by hand either way?

    You can put the code mappings into an associative array, then a single statement will get the right name.

    $schoolCodeToName = array(
        '0001' => 'school1',
        '0002' => 'school2',
        '0003' => 'school3'
        // ...
    );
    
    $school = $schoolCodeToName[ $data['school'] ];
    

    If you want to save yourself from the typing, then you need some code to load a data file and build the $schoolCodeToName array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python Script that generate a CSV (data parsed from a website).
I have the following python code that expects data coming from the serial port,
I have a script that submits data via an ajax POST. It is called
I have a script that reads a list of addresses from a table and
I have a PHP script where it is pretty important that POST data is
I'm creating a PHP script that imports some data from text files into a
I have some code that removes HTML tags from text. I don't care about
Just to give you an example: I have a PHP script that manages users
I have script that reads remote file content and writes it to local server.
I have this script that run to fix my menu bar to the browser

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.