<?php $testString = <<<EOF id1 name1 lastname1 age1 birthdate1 id2 name2 lastname2 age2 birthdate2 id3 name3 lastname3 age3 birthdate3 id4 name4 lastname4 age4 birthdate4 EOF; $stringArray = explode("\n", $testString); $finalArray = array(); foreach ($stringArray as $lineNo => $line) { $strArray = str_getcsv($line, ' ', ''); $firstVal = array_shift($strArray); $finalArray[$firstVal] = array_combine(array( 'name', 'lastname', 'age', 'birthdate' ),$strArray ); } print_r($finalArray);
You have javascript disabled. You will not be able to edit any code.