php - Editing multiple array values (if they exist) -
Well I'm struggling about this for about 5 hours and I know that my brain is fried I thought I had some better people who know what they are doing: p Now I have explained the problem properly.
I want to display all goal scorers with their name and target time for each different goal such as: Carlton Dixon (23, 53) Denniel Taskar (1).
The only way I can think of doing this is to replace the array with a new one in which the element has all the goals, then with all those targets, make a line for the name and one line, maybe I Do not see me right?
Cheers dood
array (8) {[0] = & gt; Array (3) {["fname"] = & gt; String (7) "Carlton" ["snom"] = & gt; String (7) "Dickson" ["Time"] = & gt; String (2) "23"} [1] = & gt; Array (3) {["fname"] = & gt; String (7) "Carlton" ["snom"] = & gt; String (7) "Dickson" ["Time"] = & gt; String (2) "53"} [2] = & gt; Array (3) {["fname"] = & gt; String (6) "Daniel" ["snom"] = & gt; String (6) "Taskar" ["Time"] = & gt; String (1) "1"}
You can rebuild your array like this: < / P> $ newArray = array (); Forex Currency ($ array as $ player) {$ name = $ player ['fname'] "" $ player ["SNAME"]; If (! Array_key_exists ($ name, $ newArray)) {$ newArray [$ name] = array (); } $ Newer [$ name] [] = $ player ['time']; Array ([Carlton Dixon] = & gt; Array ([0] => 23 [1] =)
& gt; 53) [Daniel Tasker] => Array ([0] = & gt; 1))
is the key name, and the value is an array of targets. Of course you can add targets as a string, Depending on the matter what else you want to do with the data.
Then printing is just a matter of crossing the array:
foreach ($ newArray $ player = & gt; $ targets) {echo $ player "( "Implode (',', target $).")
"; // or PHP_EOL}
Comments
Post a Comment