frankx: array gruppieren und zusammenzählen

Beitrag lesen

Hellihello

  
  
<?php  
  
// create test array  
$single_ratings[0]["Name"] = "Hans1";  
$single_ratings[0]["Punkte"] = "1";  
$single_ratings[1]["Name"] = "Hans1";  
$single_ratings[1]["Punkte"] = "1";  
$single_ratings[2]["Name"] = "Hans2";  
$single_ratings[2]["Punkte"] = "1";  
$single_ratings[3]["Name"] = "Hans2";  
$single_ratings[3]["Punkte"] = "1";  
  
//create assoc array with playername as key  
foreach ($single_ratings as $single_rate) {  
 $persons[$single_rate["Name"]]=0;  
}  
  
//add each single rating to player"account"  
foreach ($single_ratings as $single_rate) {  
 // does key exists in persons assoc array?  
 if(isset($persons[$single_rate["Name"]])) {  
  $persons[$single_rate["Name"]] += $single_rate["Punkte"];  
 }  
}  
//test result - expects to persons with two points  
var_dump($persons);  
?>  
  

sorry, hab ich selfst gemacht.

Dank und Gruß,

frankx

--
tryin to multitain  - Globus = Planet != Welt