如何使用php使用下面的数组创建多维数组

I have the array like given below

Array ( [id] => 1 [businessunit_id] => 1 [service_name] => dropbox [file_path] => /home/john/Desktop/GoogleDrive/alfresco_details.txt [attribute] => App key [value] => wlvii0k1bdm5lk8 )

Array ( [id] => 1 [businessunit_id] => 1 [service_name] => dropbox [file_path] => /home/john/Desktop/GoogleDrive/alfresco_details.txt [attribute] => App secret [value] => eui9d7p62qvxt78 )

Array ( [id] => 1 [businessunit_id] => 1 [service_name] => dropbox [file_path] => /home/john/Desktop/GoogleDrive/alfresco_details.txt [attribute] => Accesstoken [value] => IwSMaEYuDMAAAAAAAAAAC5jf8SyEXQUdf65xCrzFDbqrtlVyPQoJ7OBV1BRyHqqp )

Array ( [id] => 2 [businessunit_id] => 2 [service_name] => s3 [file_path] => /home/john/Desktop/GoogleDrive/alfresco_details.txt [attribute] => AWS_ACCESS_KEY_ID [value] => xxx )

Array ( [id] => 2 [businessunit_id] => 2 [service_name] => s3 [file_path] => /home/john/Desktop/GoogleDrive/alfresco_details.txt [attribute] => AWS_SECRET_ACCESS_KE [value] => xxxxxx )

I want it to convert like below

Array ( [id] => 1 [businessunit_id] => 1 [service_name] => dropbox [file_path] => /home/john/Desktop/GoogleDrive/alfresco_details.txt array([App key] =>wlvii0k1bdm5lk8, [App secret] =>eui9d7p62qvxt78, [Accesstoken] =>IwSMaEYuDMAAAAAAAAAAC5jf8SyEXQUdf65xCrzFDbqrtlVyPQoJ7OBV1BRyHqqp ))

Array ( [id] => 2 [businessunit_id] => 2 [service_name] => s3 [file_path] => /home/john/Desktop/GoogleDrive/alfresco_details.txt array([AWS_ACCESS_KEY_ID] => xxx, [AWS_SECRET_ACCESS_KE] =>xxxxxx) ) 

unable to get the expected result. could you please some one help me out

here is my php code:

while($row = $result->fetch_assoc()) {

    $curid = $row['id'];
    //$pastid = $curid;

        echo '<pre>';
    //print_r($row);

    if($i == 0){

        $newarray[$i]['id'] =  $row['id'];
        $newarray[$i]['businessunit_id'] =  $row['businessunit_id']; 
        $newarray[$i]['file_path'] =  $row['file_path'];
        $newarray[$i]['service_name'] =  $row['service_name'];
        $newarray[$i][$row['attribute']] =  $row['value'];  

    } else {

        if($newarray[$i-1]['id'] == $curid){
            $newarray[$i-1][$row['attribute']] =  $row['value'];
            $newarray[$i]['id'] =  $row['id'];          
        } else{
            $newarray[$i]['id'] =  $row['id'];
            $newarray[$i]['businessunit_id'] =  $row['businessunit_id']; 
            $newarray[$i]['file_path'] =  $row['file_path'];
            $newarray[$i]['service_name'] =  $row['service_name'];
            $newarray[$i][$row['attribute']] =  $row['value'];
        }
    }
    $i++;

}

Basically, you're trying to diff the arrays and combine the diff results with the intersect of the three arrays.

//untested code sample
function reformatArrays($arrays)
{
     $diff = [];
     $a = reset($arrays);
     $inter = [];
     foreach($array as $k => $v)
     {
         $diff[] = array_diff($a, $v);
         $inter = array_intersect($a, $v);
         $a = $v;
     }
     return $inter + $diff;
}

try this, where $origin is your current array:

$result = array();
foreach($origin as $a)
{
    if(!isset($result[$a['id']]))
    {
        $result[$a['id']] = array('id' => $a['id'], 'businessunit_id' => $a['businessunit_id'], 'service_name' => $a['service_name'], 'file_path' => $a['file_path'] );
    }
    $result[$a['id']]['appvalues'][$a['attribute']] = $a['value'];
}