PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP.

I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you have an idea how to solve this the best way, I would be happy if someone could tell me.

I fetch a dataset and prepared it that it looks almost always the same.

The lenght (amount of rows) could be larger or shorter.
If there is a LOW somewhere in the dataset, a database field which was 'high' for the previous rows has to be 'low' from there on for the following rows, and high again for the next set of data to be fetched.

I have stored this fetched example data into a string, and it looks like this:

0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 1.0;analog, 6.008031845092773,'11.100.000', '1.000.000', 11100000, 1000000, 0.93333334,�1,01, 1007354,1 - 3, 2,0,0,0,,BR,0 ; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 1.0;analog, 6.008031845092773,'6.120.000', '550.000', 6120000, 550000, 0.93333334,�1,01, 1007354,1 - 3, 2,0,0,0,,EX,0 ; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 1.0;analog, 6.008031845092773,'11.100.000', '1.000.000', 11100000, 1000000, 0.93333334,�1,01, 1007354,1 - 3, 2,0,0,0,,PH,0 ; LOW 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ;new analog, 4.548180103302002,'nicht ausreichend', '110', -1, 110, 0.46666667,�0,05, 50000,1 - 3, 2,0,0,-1,-new,BR,0 ;  0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ;new analog, 4.548180103302002,'nicht ausreichend', '22', -1, 22, 0.46666667,�0,05, 50000,1 - 3, 2,0,0,-1,,EX,0 ;  0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ;new analog, 4.548180103302002,'nicht ausreichend', '46', -1, 46, 0.46666667,�0,05, 50000,1 - 3, 2,0,0,-1,,PH,0 ;

The Fields are delimeted by comma or semikolon, the dataset is delimeted by ,0 ;

The Plan is, to split the data into two variables first, so I get the High and Low data.

Then, for each variable, split its content into a multidimensional array containing the rows, delimitted by ',0;'

explode(',0;', $low);
0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 1.0;analog,  6.008031845092773,'11.100.000', '1.000.000', 11100000, 1000000,  0.93333334,�1,01, 1007354,1 - 3, 2,0,0,0,,BR,0 ;

0.0; 0.0; 0.0;  0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 1.0;analog,  6.008031845092773,'6.120.000', '550.000', 6120000, 550000,  0.93333334,�1,01, 1007354,1 - 3, 2,0,0,0,,EX,0 ;

and then split again to the fields delimeted by Comma or Semkolon

 preg_split("/[;,]+/" 

0.0
0.0
0.0
...
0,

EX
0

How would be the the correct syntax to read the array and assign each array field a database field and store it into a database. I have to do it row by row I think... and take care of high and low

 
Field 'type' ==> 'high'

0.0 => 'Jan'
0.0 => 'Feb'
0.0 => 'March'
...
0, => 'Field xx'

EX => 'Field xy'
0 => 'Field zz'

Any ideas about this are welcome :slight_smile: