YOMAMA Suspended 6218 Posts user info edit post |
I have an array that is structured like this:
[players] => Array ( [0] => Array ( [name] => [DC]ClavisApocalyptica* [ping] => 42 [team] => 2 [score] => 20 [deaths] => 6 [keyhash] => 71b222c664a8f9ea56d0f1c80cfb28e5 [kills] => 14 )
[1] => Array ( [name] => SalamiFlavoredSpider [ping] => 50 [team] => 1 [score] => 7 [deaths] => 8 [keyhash] => 73f0f13b6e09c1fc812de7bd74648d24 [kills] => 5 ) )
And it is displayed like this:
name: BLAH BLAH ping: 42 team: 2 score: 2 deaths: 0 keyhash: 71b222c664a8f9ea56d0f1c80cfb28e5 kills: 0
name: BLAH BLAH ping: 91 team: 1 score: 0 deaths: 1 keyhash: e25281cf1daf87dfc663023cb2ca7830 kills: 0
This array can return around 60 total blocks at anytime. What I am trying to do is have it return only those with the value
[team] => 1
Can anyone advise on what I might do to accomplish this?
Thanks!1/31/2006 6:38:51 PM |
Excoriator Suspended 10214 Posts user info edit post |
team1 = setof(i players players[i][team] == "1")
print(team1)
(since you didn't specify which language you were losing, i picked for myself)
[Edited on January 31, 2006 at 7:59 PM. Reason : s]1/31/2006 7:58:29 PM |
YOMAMA Suspended 6218 Posts user info edit post |
sorry PHP 1/31/2006 8:33:54 PM |
Stein All American 19842 Posts user info edit post |
for ($i = 0; $i < sizeof($players); $i++){ if ($players[$i]['team'] == 1){ // do whatever } }
Actually, this seems to work as well:
function saveTeam($val){ return ($val['team'] == 1); } array_filter($players, "saveTeam");
Though really, you should just use a database.
[Edited on February 1, 2006 at 4:51 PM. Reason : .]2/1/2006 4:43:07 PM |
YOMAMA Suspended 6218 Posts user info edit post |
No why would i do that?
People are always changing teams and all values change every second.
Its a live script so DB is out of the question.
I ended up using the Smarty Template System.
Pretty cool if you ask me. 2/1/2006 5:18:15 PM |
Stein All American 19842 Posts user info edit post |
Well, in that case you obviously shouldn't.
The code above will give you the array you want all the same. 2/1/2006 8:21:43 PM |