mysql - Array group by key PHP CodeIgniter -
i have following response php code.
array ( [customer] => 402 [carat] => array ( [0] => 6 [1] => 5 ) [units] => array ( [0] => grams [1] => dwt [2] => dwt ) [weight] => array ( [0] => 5 [1] => 3 [2] => 6 ) [our_payout] => array ( [0] => 15 [1] => 9 [2] => 60 ) [sale_payout] => array ( [0] => 18 [1] => 12 [2] => 180 ) [hidden_carat] => array ( [0] => 6 [1] => 5 [2] => ) [hidden_unit] => array ( [0] => 1 [1] => 2 [2] => 2 ) [carat_scale_price] => array ( [0] => [1] => [2] => ) [sales_id] => array ( [0] => [1] => [2] => ) [currency_rate_id] => array ( [0] => [1] => [2] => ) [gold_price_id] => array ( [0] => [1] => [2] => ) [taget_percentage] => [reference] => 0 [notes] => [unit] => 0 [customer_id] => 402 [total_items] => 2 [submit] => ) and want join example [0] => grams [0] => 5 [0] => 16 , on. how can that?
i'm steve, i'm not sure you're asking for. looks want transpose matrix of keys? here's might you're looking for, assuming original array above in variable $arr:
$lineitems = array(); $i = 0; $alllineitemshavei = true; while($alllineitemshavei) { $lineitems[$i] = array(); foreach($arr $key => $subarr) { if(array_key_exists($i, $subarr)) { $lineitems[$i][$key] = $subarr[$i]; } else { $alllineitemshavei = false; } } $i++; } array_pop($lineitems); this output:
array ( [0] => array ( [carat] => 6 [units] => grams [weight] => 5 [our_payout] => 15 [sale_payout] => 18 [hidden_carat] => 6 ) [1] => array ( [carat] => 5 [units] => dwt [weight] => 3 [our_payout] => 9 [sale_payout] => 12 [hidden_carat] => 5 ) ) also, check out: transposing multidimensional arrays in php
Comments
Post a Comment