PHP - 按键/值分割多维数组

Mos*_*tia -2 php multidimensional-array

我想转换这个多维数组:

array(
[0] => array (
   "interest_income-bank" => "520.541"
   "total_interest_expense" => "145.791"
   "net_interest_income" => "434.937"
   "loan_loss_provision" => "135.664"
   .
   .
)
[1] => array (
   "interest_income-bank" => "617.894"
   "total_interest_expense" => "205.508"
   "net_interest_income" => "506.510"
   "loan_loss_provision" => "120.586"
   .
   .    
)
)
Run Code Online (Sandbox Code Playgroud)

到这样的数组:

array(
[interest_income-bank] => array (
   "0" => "520.541"
   "1" => "617.894"
   .
   .
)
[total_interest_expense] => array (
   "1" => "145.791"
   "2" => "205.508"
   .
   .
)
)
Run Code Online (Sandbox Code Playgroud)

尝试了很多但没有运气:(

任何帮助将非常感激!

Don*_*nic 6

迭代外部数组,然后迭代内部数组。将每个值添加到结果中的索引数组中。

foreach ($your_array as $sub_array) {
    foreach ($sub_array as $key => $value) {
        $result[$key][] = $value;
    }
}
Run Code Online (Sandbox Code Playgroud)