Zugzwangle Posted August 4, 2010 Share Posted August 4, 2010 hello. i have the following array called $newParts which cycles through game data: [0] => Control 90m + 5s, rated <--start of game 1 [1] => Site Room 1 [2] => Date 2010.08.03 [3] => Round ? [4] => WhiteIs D r A G ó N [5] => BlackIs Spike_and_Butch [6] => Result 0-1 <--end of game 1 [7] => Control 90m + 5s, rated <--start of game 2 [8] => Site Room 1 [9] => Date 2010.08.03 [10] => Round ? [11] => WhiteIs Öschi [12] => BlackIs Shreki [13] => Result 1/2-1/2 <--end of game 2 ---> continues with next game data... The games all start with "Control " and end with "Result " Firstly, I would like to split the array into seperate game arrays. How would I go about doing this? Secondly, I would like to use the first word, of the values in the new arrays, as the Key. So the arrays would become: [site] => Room 1 [Date] => 2010.08.03 [Round] => ? [WhiteIs] => D r A G ó N [blackIs] => Spike_and_Butch [Result] => 0-1 Any help would be greatly appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/209778-spllitting-array-and-changing-keys/ Share on other sites More sharing options...
trq Posted August 4, 2010 Share Posted August 4, 2010 Have you attempted to write any code for this? Its just a matter of thinking the problems through logically. Quote Link to comment https://forums.phpfreaks.com/topic/209778-spllitting-array-and-changing-keys/#findComment-1095069 Share on other sites More sharing options...
Zugzwangle Posted August 4, 2010 Author Share Posted August 4, 2010 yes.. ive tried again and again to do this, but im not sure how to go about it.. Quote Link to comment https://forums.phpfreaks.com/topic/209778-spllitting-array-and-changing-keys/#findComment-1095071 Share on other sites More sharing options...
dolrichfortich Posted August 4, 2010 Share Posted August 4, 2010 Try this script. <?php $game_data = array( 'Control 90m + 5s, rated', 'Site Room 1', 'Date 2010.08.03 ', 'Round ?', 'WhiteIs D r A G ó N', 'BlackIs Spike_and_Butch', 'Result 0-1', 'Control 90m + 5s, rated', 'Site Room 1', 'Date 2010.08.03', 'Round ?', 'WhiteIs Öschi', 'BlackIs Shreki', 'Result 1/2-1/2' ); $new_array = array(); $game_data_count = count($game_data); if($game_data_count) { for($i = 7; $i <= $game_data_count; $i += 7) { $new_array[] = array( 'control' => $game_data[$i-7], 'site' => $game_data[$i-6], 'date' => $game_data[$i-5], 'round' => $game_data[$i-4], 'whiteis' => $game_data[$i-3], 'blackis' => $game_data[$i-2], 'result' => $game_data[$i-1] ); } } print_r($new_array); ?> Quote Link to comment https://forums.phpfreaks.com/topic/209778-spllitting-array-and-changing-keys/#findComment-1095073 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.