php - Bidimensional array generated dynamically -
i'm working dynamic data, i'm trying put data bidimensional array.
i need structure this:
$array['something1'] = array ( 'hi1' => 'there1' , 'hi2' => 'there2' ); all data dynamically generated foreach, ex.:
$list = array ( 0 => 'something;hi1;there1' , 1 => 'something;hi2;there2' ); foreach ( $list $key => $data ) { // extract data $columns = explode ( ';' , $data ); // set data $items[$columns[0]] = array ( $columns[1] => $columns[2] ); } how can described?
right script stepping on previous key getting this:
$array['something1'] = array ( 'hi2' => 'there2' ); i hope can me.
thanks.
the problem overwriting value key when exists. should modify like:
foreach ( $list $key => $data ) { // extract data $columns = explode ( ';' , $data ); $outer_array_key = $columns[0]; $key = $columns[1]; $value = $columns[2]; // set data $items[$outer_array_key][$key] = $value; }
Comments
Post a Comment