php - Multidimensional array, how do I solve this? -
i've been trying solve this, keep getting "gained" output instead of user.
array(2) { ["skill"]=> array(2) { [0]=> array(2) { ["user"]=> string(7) "username" ["gained"]=> int(15) } [1]=> array(2) { ["user"]=> string(6) "username" ["gained"]=> int(8) } [2]=> array(2) { ["user"]=> string(6) "username" ["gained"]=> int(3) } ["skill2"]=> array(2) { [0]=> array(2) { ["user"]=> string(7) "username" ["gained"]=> int(10) } [1]=> array(2) { ["user"]=> string(6) "username" ["gained"]=> int(7) } [2]=> array(2) { ["user"]=> string(6) "username" ["gained"]=> int(5) } }
i want output:
username ranked 1 gained 15<br/> username ranked 2 gained 8<br/> username ranked 3 gained 3<br/> <br/><br/> ["skill2"]:<br/> username ranked 1 gained 10<br/> username ranked 2 gained 7<br/> username ranked 3 gained 5<br/> <br/><br/>
the array sorted "gained".
user ranked $loopruns gained $gained
foreach($ar1 $skill => $value) { $i = 0; echo "<b>skill: $skill</b><br/>"; foreach($value $ar2 => $ar3) { foreach($ar3 $key => $value) { $i++; echo "$key ranked #$i gained $value<br/>"; } } echo "<br/>"; }
foreach($skillarray $skillname => $players) { echo "skill: ".$skillname."<br/>"; foreach($players $rank => $data) { echo $data["user"]." ranked ".$rank." gained ".$data["gained"]." <br/>"; } echo "<br/>"; }
explanation
first loop "visit" 2 main branches (skill
, skill1
). values (as array keys) holded $skillname
variable, while whole player array, keep $players
variable.
have loop through every user. that, write foreach
keys hold player position (ok, 0 index, if want can add unit it) , data
contain data.
Comments
Post a Comment