Php 从多维数组创建唯一ID

Php 从多维数组创建唯一ID,php,Php,我有一个数组,下面有一个小例子 Array (2) system => Array (1) system_id => 3 proc => Array (4) proc_id => 5 proc_or => 1 proc_owner => 7751 results => Array (7) 0 => Array (5) process_id => 101 process => 1335

我有一个数组,下面有一个小例子

Array (2)
system => Array (1)
  system_id => 3
proc => Array (4)
  proc_id => 5
  proc_or => 1
  proc_owner => 7751
  results => Array (7)
    0 => Array (5)
      process_id => 101
      process => 1335
      process_name => xa
      process_owner => xo
      rating => 67.554
    1 => Array (6)
      process_id => 122
      process => 1335
      process_name => xa
      process_owner => xo
      rating => 33.554
      proc_rel => xf    
    2 => Array (5)
      process_id => 101
      process => 1227
      process_name => xd
      process_owner => xa
      rating => 123.78
    3 => Array (8)
      process_id => 101
      process => 1291
      process_name => xa
      process_owner => xo
      rating => 64.241
      proc_rel => xf
      proc_rel_id => 1474
      proc_rel_owner => xm
我需要能够组织它,以便它只包含唯一的进程id值,这样结果2和3将被删除,剩余唯一id的评级是具有该id的记录的所有评级的总和,因此结果0评级id将成为结果0 2和3的总和

有数千条记录,因此如果没有某种自动循环,就不太实际

我在考虑创建一个新数组,并在处理过程中

如果进程id不在新数组中,请添加它和所有相关数据 如果进程id已经在数组中,只需将额定值(+)添加到现有值

我试着调整了我发现的几个循环,但它们似乎不能正常工作


不确定这是否是一种方法,我也不确定怎么做,因此非常感谢您的建议。

如果数据集很大,那么最好在生成查询时调整数据库查询或更改文件结构。如果不可能,那么唯一合理的方法是创建新阵列:

$newArray = ();
foreach($array['proc']['results'] as $result) {
    if (isset($newArray[$result['process_id']]) {
        $newArray[$result['process_id']]['rating'] += $result['rating'];
    } else {
        $newArray[$result['process_id']] = $result;
    }
}

在哪里生成数据。如果来自数据库,则可以设置查询并调整输出。