J'ai un tableau de php comme ceci
Array
(
[0] => Array
(
[Sr_No] => 1
[Asan_Category] => Warm-Up
[Asan_Cat_Val] => 8
[Asan_Sub_Category] => Ankle
[Asan_Sub_Cat_Val] => 35
[Asan_Name] => General Ankle Warm up
[Asan_Name_Val] => 447
[Prescribed_Steps] => 40
[Prescribed_Ratio] => 00
[Actual_Steps] => 12
[Actual_Ratio] => 0
)
[1] => Array
(
[Sr_No] => 2
[Asan_Category] => Warm-Up
[Asan_Cat_Val] => 8
[Asan_Sub_Category] => Knee
[Asan_Sub_Cat_Val] => 111
[Asan_Name] => General knee warm up
[Asan_Name_Val] => 464
[Prescribed_Steps] => 20
[Prescribed_Ratio] => 00
[Actual_Steps] => 14
[Actual_Ratio] => 0
)
[2] => Array
(
[Sr_No] => 1
[Asan_Category] => Warm-Up
[Asan_Cat_Val] => 8
[Asan_Sub_Category] => Ankle
[Asan_Sub_Cat_Val] => 35
[Asan_Name] => General Ankle Warm up
[Asan_Name_Val] => 447
[Prescribed_Steps] => 40
[Prescribed_Ratio] => 00
[Actual_Steps] => 10
[Actual_Ratio] => 0
)
[3] => Array
(
[Sr_No] => 2
[Asan_Category] => Warm-Up
[Asan_Cat_Val] => 8
[Asan_Sub_Category] => Knee
[Asan_Sub_Cat_Val] => 111
[Asan_Name] => General knee warm up
[Asan_Name_Val] => 464
[Prescribed_Steps] => 20
[Prescribed_Ratio] => 00
[Actual_Steps] => 9
[Actual_Ratio] => 0
)
)
The desired output I want
Array
(
[0] => Array
(
[Asan_Id] => 447
[Asan_Category] => Warm-Up
[Asan_Sub_Category] => Ankle
[Asan_Name] => General Ankle Warm up
[Prescribed_Steps] => 40
[Prescribed_Ratio] => 00
[Total_Steps] => 22
)
[1] => Array
(
[Asan_Id] => 464
[Asan_Category] => Warm-Up
[Asan_Sub_Category] => Knee
[Asan_Name] => General knee warm up
[Prescribed_Steps] => 20
[Prescribed_Ratio] => 00
[Total_Steps] => 23
)
)
Je veux que ces données qui se répètent deviennent une seule mais leurs différentes étapes réelles deviennent des étapes totales avec leur somme. S'il vous plaît aidez-moi parce que j'ai essayé un certain code mais n'a pas réussi comme ceci
$asan=[];
$total_steps=0;
foreach ($aasan_details as $key) {
$total_steps += $key['Actual_Steps'];
if(!in_array($key['Asan_Name_Val'],$asan))
{
$asan[] = $key['Asan_Name_Val'];
$lookup[] = array("Asan_Id"=>$key['Asan_Name_Val'],
"Asan_Category"=>$key['Asan_Category'],
"Asan_Sub_Category"=>$key['Asan_Sub_Category'],
"Asan_Name"=>$key['Asan_Name'],
"Prescribed_Steps"=>$key['Prescribed_Steps'],
"Prescribed_Ratio"=>$key['Prescribed_Ratio'],
'Total_Steps'=>$total_steps);
}
}
Cela ne fonctionne pas, que dois-je faire, s'il vous plaît, aidez-moi.
où $aasan_details
est le tableau que j'ai montré ci-dessus et dans le tableau de recherche, j'obtiens des valeurs uniques mais pas leur total.
0 votes
Excusez-moi, mais le total des étapes contient la somme par identifiant
0 votes
Pouvez-vous fournir un
var_export
sortie des données fictives ?0 votes
Asan Id est le nom asan val