poe Posted November 20, 2006 Share Posted November 20, 2006 i have this array of game odds:[quote]Array( [0] => Array( [gameid] => 23 [odds_V+] => 2.85 [ovun] => [visitor] => PIT [home] => PHI ) [1] => Array( [gameid] => 23 [odds_V] => 1.85 [ovun] => [visitor] => PIT [home] => PHI ) [2] => Array( [gameid] => 23 [odds_T] => 6.0 [ovun] => [visitor] => PIT [home] => PHI ) [3] => Array( [gameid] => 23 [odds_H] => 1.75 [ovun] => [visitor] => PIT [home] => PHI ) [4] => Array( [gameid] => 23 [odds_H+] => 2.7 [ovun] => [visitor] => PIT [home] => PHI ) [5] => Array( [gameid] => 23 [odds_O] => 1.6 [ovun] => 6.5 [visitor] => PIT [home] => PHI ) [6] => Array( [gameid] => 23 [odds_U] => 1.8 [ovun] => 6.5 [visitor] => PIT [home] => PHI ) [7] => Array( [gameid] => 24 [odds_V] => 2.1 [ovun] => [visitor] => CROS [home] => GAGN ) [8] => Array( [gameid] => 24 [odds_T] => 4.0 [ovun] => [visitor] => CROS [home] => GAGN ) [9] => Array( [gameid] => 24 [odds_H] => 2.2 [ovun] => [visitor] => CROS [home] => GAGN ) [10] => Array( [gameid] => 26 [odds_V] => 2.1 [ovun] => [visitor] => SULL [home] => NASH ) [11] => Array( [gameid] => 26 [odds_T] => 4.0 [ovun] => [visitor] => SULL [home] => NASH ) [12] => Array( [gameid] => 26 [odds_H] => 2.2 [ovun] => [visitor] => SULL [home] => NASH ))[/quote]each array represents a different type of oddsie. V+ = visitor win by 2, T = tie, H = home win by 1, U = under the over/under score etc...i want to group each array by the 'gameid'notice how for teams (gameid 23), it is made up of 7 different arrays - V+, V, T, H, H+, O, Uhowever players(gameid 24 & 26) are made up of 3 arrays. V, T, Hhere is what i want:[quote]Array( [0] => Array( [gameid] => 23 [odds_V+] => 2.85 [odds_V] => 1.85 [odds_T] => 6.0 [odds_H] => 1.75 [odds_H+] => 2.7 [odds_O] => 1.6 [odds_U] => 1.8 [ovun] => 6.5 [visitor] => PIT [home] => PHI ) [1] => Array( [gameid] => 24 [odds_V] => 2.1 [odds_T] => 4.0 [odds_H] => 2.2 [ovun] => [visitor] => CROS [home] => GAGN ) [2] => Array( [gameid] => 26 [odds_V] => 2.1 [odds_T] => 4.0 [odds_H] => 2.2 [ovun] => [visitor] => SULL [home] => NASH ))[/quote] Quote Link to comment Share on other sites More sharing options...
sasa Posted November 20, 2006 Share Posted November 20, 2006 try[code]<?php$a=Array( '0' => Array( 'gameid' => '23', 'odds_V+' => '2.85', 'ovun' =>'', 'visitor' => 'PIT', 'home' => 'PHI' ), '1' => Array( 'gameid' => '23', 'odds_V' => '1.85', 'ovun' =>'', 'visitor' => 'PIT', 'home' => 'PHI' ), '2' => Array( 'gameid' => '23', 'odds_T' => '6.0', 'ovun' =>'', 'visitor' => 'PIT', 'home' => 'PHI' ), '3' => Array( 'gameid' => '23', 'odds_H' => '1.75', 'ovun' =>'', 'visitor' => 'PIT', 'home' => 'PHI' ), '4' => Array( 'gameid' => '23', 'odds_H+' => '2.7', 'ovun' =>'', 'visitor' => 'PIT', 'home' => 'PHI' ), '5' => Array( 'gameid' => '23', 'odds_O' => '1.6', 'ovun' => '6.5', 'visitor' => 'PIT', 'home' => 'PHI' ), '6' => Array( 'gameid' => '23', 'odds_U' => '1.8', 'ovun' => '6.5', 'visitor' => 'PIT', 'home' => 'PHI' ), '7' => Array( 'gameid' => '24', 'odds_V' => '2.1', 'ovun' =>'', 'visitor' => 'CROS', 'home' => 'GAGN' ), '8' => Array( 'gameid' => '24', 'odds_T' => '4.0', 'ovun' =>'', 'visitor' => 'CROS', 'home' => 'GAGN' ), '9' => Array( 'gameid' => '24', 'odds_H' => '2.2', 'ovun' =>'', 'visitor' => 'CROS', 'home' => 'GAGN' ), '10' => Array( 'gameid' => '26', 'odds_V' => '2.1', 'ovun' =>'', 'visitor' => 'SULL', 'home' => 'NASH' ), '11' => Array( 'gameid' => '26', 'odds_T' => '4.0', 'ovun' =>'', 'visitor' => 'SULL', 'home' => 'NASH', ), '12' => Array( 'gameid' => '26', 'odds_H' => '2.2', 'ovun' =>'', 'visitor' => 'SULL', 'home' => 'NASH' ));foreach ($a as $b) $out[$b['gameid']] = ($out[$b['gameid']]) ? array_merge($out[$b['gameid']], $b) : $out[$b['gameid']] = $b;print_r($out);// orforeach ($out as $b) $out1[] = $b;print_r($out1);?> [/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.