php - Sorting query result to associative array with optional keys -


using php running query on database , result data-set optional values. example:

result: array   (      [0] => array        (          [attribute_1] => red,          [attribute_2] => car,          [name] => sportscar        )      [1] => array        (          [attribute_1] => red,          [attribute_2] => ,          [name] => rose        )   ) 

i want format resulting data such:

array    (        [red] => array          (             [car] => array                   (                     [0] => sportscar                   )          )       [0] => rose    )  

so access sportscar by

$array['red']['car'][0]; 

and rose by

$array['red'][0] 

this make easier output data nice little foreach loop.

of course actual case bit more complex lot more values etc example demonstrates principle.

the problem can't think of proper way format data efficiently. not recursive @ least not 1 million if , elses nice.

any ideas?


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -