php - Create 2 dimensional merged array based value -
i have array in following format,
array ( [0] => array ( [expense_id] => 7 [type] => frfrf [mode] => rfr [amount] => 100 [tran_type] => expense [date] => 2015-06-29 ) [1] => array ( [expense_id] => 8 [type] => frfrf [mode] => rfr [amount] => 100 [tran_type] => expense [date] => 2015-06-29 ) [2] => array ( [expense_id] => 9 [type] => frfrf [mode] => rfr [amount] => 444 [tran_type] => expense [date] => 2015-06-29 ) [3] => array ( [expense_id] => 10 [type] => frfrf [mode] => rfr [amount] => 1000 [tran_type] => income [date] => 2015-06-29 ) [4] => array ( [expense_id] => 5 [type] => frfrf [mode] => rfr [amount] => 100 [tran_type] => expense [date] => 2015-06-01 ) )
i want merge array based on date
value , store array key date
array ( [2015-06-29] => array ( [0] => array ( [expense_id] => 7 [type] => frfrf [mode] => rfr [amount] => 100 [tran_type] => expense [date] => 2015-06-29 ) [1] => array ( [expense_id] => 8 [type] => frfrf [mode] => rfr [amount] => 100 [tran_type] => expense [date] => 2015-06-29 ) [2] => array ( [expense_id] => 9 [type] => frfrf [mode] => rfr [amount] => 444 [tran_type] => expense [date] => 2015-06-29 ) [3] => array ( [expense_id] => 10 [type] => frfrf [mode] => rfr [amount] => 1000 [tran_type] => income [date] => 2015-06-29 ) ) [2015-06-01] => array ( [0] => array ( [expense_id] => 5 [type] => frfrf [mode] => rfr [amount] => 100 [tran_type] => expense [date] => 2015-06-01 ) ) )
currently i'm doing using foreach loop , there simple way this
foreach ($d $v) { $d1[$v['date']][] = $v; }
data retrieved using mysql, mysql query acceptable
i know way
$newarray = []; foreach ($array $subarray) { $newarray[$subarray['date']][] = $subarray; }
Comments
Post a Comment