Transform PHP array -


i have php array i'm trying transform different format, way can think lot longer seems should need.

example data:

array ( [0] => array (     [type] =>     [value] => 1     ) [1] => array (     [type] =>     [value] => 2     ) [2] => array (     [type] =>     [value] => 3     ) [3] => array (     [type] => b     [value] => 1     ) [4] => array (     [type] => b     [value] => 4     ) [5] => array (     [type] => f     [value] => 2     ) )  

into:

array ( 'a' => array(1,2,3), 'b' => array(1,4), 'f' => array(2) ) 

foreach ($array $element)      $newarray[$element["type"]][] = $element["value"]; 

seems trick rather nicely.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -