php - Convert a one dimensional array to two dimensional array -


i have array, structure this:

array('id,"1"', 'name,"abcd"', 'age,"30"') 

i want convert 2 dimensional array, has each element key -> value:

array(array(id,1),array(name,abcd),array(age,30)) 

any advice appreciated!

i tried code:

foreach ($datatest $lines => $value){     $tok = explode(',',$value);      $arrayoutput[$tok[0]][$tok[1]] = $value; } 

but didn't work.

assuming want remove quotation marks per question:

$oldarray = array('id,"1"', 'name,"abcd"', 'age,"30"') $newarray = array(); foreach ($oldarray $value) {   $value = str_replace(array('"',"'"), '', $value);   $parts = explode(',', $value);   $newarray[] = $parts; } 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -