J'ai un tableau.
$arr = array(
[
'amenity_id' => '4277',
'amenity_name' => 'Floor 1',
'category_id' => '380',
'amenity_value' => '0',
'unit_id' => '25253',
'unit_number' => '701',
'dom' => '50',
'building_id' => '423'
],
[
'amenity_id' => '4330',
'amenity_name' => 'Floor 7',
'category_id' => '380',
'amenity_value' => '53',
'unit_id' => '25253',
'unit_number' => '701',
'dom' => '50',
'building_id' => '423'
],
[
'amenity_id' => '4330',
'amenity_name' => 'Floor 7',
'category_id' => '380',
'amenity_value' => '53',
'unit_id' => '25253',
'unit_number' => '701',
'dom' => '20',
'building_id' => '423'
],
[
'amenity_id' => '4331',
'amenity_name' => 'Top Floor',
'category_id' => '380',
'amenity_value' => '32',
'unit_id' => '25253',
'unit_number' => '701,',
'dom' => '50',
'building_id' => '423'
],
[
'amenity_id' => '4331',
'amenity_name' => 'Top Floor',
'category_id' => '380',
'amenity_value' => '0',
'unit_id' => '25253',
'unit_number' => '701',
'dom' => '20',
'building_id' => '423'
],
);
Ici, vous pouvez voir que deux équipements avec amenity_id 4330
y 4331
sont répétées. Je souhaite fusionner ces tableaux avec le même identifiant d'équipement et calculer la valeur moyenne de amenity_value
y dom
.
Résultat attendu :
array(
[
'amenity_id' => '4277',
'amenity_name' => 'Floor 1',
'category_id' => '380',
'amenity_value' => '0',
'unit_id' => '25253',
'unit_number' => '701',
'dom' => '50',
'building_id' => '423'
],
[
'amenity_id' => '4330',
'amenity_name' => 'Floor 7',
'category_id' => '380',
'amenity_value' => '53',//(53+53)/2
'unit_id' => '25253',
'unit_number' => '701',
'dom' => '35',//(50+20)/2
'building_id' => '423'
],
[
'amenity_id' => '4331',
'amenity_name' => 'Top Floor',
'category_id' => '380',
'amenity_value' => '16', //(32+0)/2
'unit_id' => '25253',
'unit_number' => '701,'
'dom' => '35',//(50+20)/2
'building_id' => '423'
],
);
Note : Il peut y avoir plus de deux éléments avec le même numéro d'agrément, c'est pourquoi nous devons trouver la moyenne.