转移一系列对象[重复]

问题描述 投票:0回答:2
[1]=> array(2) { [0]=> object(stdClass)#23 (7) { ["AddressesTableID"]=> string(1) "8" ["AccreditNo"]=> string(13) "5129876de28ff" ["Type"]=> string(4) "home" ["Street"]=> string(34) "Wallace, Village, Under the bridge" ["Municipality"]=> string(8) "Tortuous" ["Province"]=> string(8) "Sardonic" ["ContactNo"]=> string(8) "92012010" } [1]=> object(stdClass)#24 (7) { ["AddressesTableID"]=> string(1) "9" ["AccreditNo"]=> string(13) "5129876de28ff" ["Type"]=> string(6) "office" ["Street"]=> string(25) "Rasputin Query, Palpitate" ["Municipality"]=> string(7) "Opulent" ["Province"]=> string(6) "Number" ["ContactNo"]=> string(8) "29101011" } }

你们可以帮助我如何将其转变为:

所有值将所有值分组为类似的键?

["AccreditNo"]=> array(2) { "5129876de28ff", "GKIJUGUIKGI" } ["Type"]=> array(2) { "home", "home" } ["Street"]=> ... ["Municipality"]=> ... ["Province"]=> ... ["ContactNo"]=> ...

tron与:

$input  = array( /* your input data*/ );
$output = array();

foreach ( $input as $data ) {
  foreach ( $data as $key => $value ) {
    if ( !isset($output[$key]) ) {
      $output[$key] = array();
    }
    $output[$key][] = $value;
  }
}
php arrays multidimensional-array transpose
2个回答
2
投票
您可以使用array_merge_recursive()函数,如下:

$arr = array_merge_recursive($arr1, $arr2)
有关更多信息,请参阅此处:

2
投票


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.