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?
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.
If you want to save yourself from the typing, then you need some code to load a data file and build the
$schoolCodeToNamearray.