<?php
// Dados de entrada:
$linha = 'NICK:KEOME PTS:50 ASTS:6 DEFREB:2 OFFREB:7 STLS:14 BLKS:4 TOS:5 NICK:ARTHUR PTS:10 ASTS:3 DEFREB:5 OFFREB:4 STLS:4 BLKS:2 TOS:6';
// Verifica se é possível obter os dados com expressão regular:
if (preg_match_all("/([a-zA-Z]+)\:([a-zA-Z0-9]+)\s?/", $linha, $matches)) {
// Lista de jogadores:
$players = [];
// Dados do jogador:
$player = [];
// Percorre todos os valores da entrada:
foreach(array_map(null, $matches[1], $matches[2]) as $pair) {
// O valor é um nick?
// Se houver dados de outro jogador, adicione a lista:
if ($player) {
$players[] = $player;
}
// Inicia os dados do jogador para o nick atual:
$player = ["name" => $pair[1], "stats" => []];
} else {
// Não é um nick, então só pode ser um status do jogador atual:
$player["stats"][strtolower($pair[0])] = $pair[1]; }
}
// Adiciona à lista os dados do último jogador:
if ($player) {
$players[] = $player;
}
// Exibe a lista de jogadores completa:
}
PD9waHAKCi8vIERhZG9zIGRlIGVudHJhZGE6CiRsaW5oYSA9ICdOSUNLOktFT01FIFBUUzo1MCBBU1RTOjYgREVGUkVCOjIgT0ZGUkVCOjcgU1RMUzoxNCBCTEtTOjQgVE9TOjUgTklDSzpBUlRIVVIgUFRTOjEwIEFTVFM6MyBERUZSRUI6NSBPRkZSRUI6NCBTVExTOjQgQkxLUzoyIFRPUzo2JzsKCi8vIFZlcmlmaWNhIHNlIMOpIHBvc3PDrXZlbCBvYnRlciBvcyBkYWRvcyBjb20gZXhwcmVzc8OjbyByZWd1bGFyOgppZiAocHJlZ19tYXRjaF9hbGwoIi8oW2EtekEtWl0rKVw6KFthLXpBLVowLTldKylccz8vIiwgJGxpbmhhLCAkbWF0Y2hlcykpIHsKCiAgLy8gTGlzdGEgZGUgam9nYWRvcmVzOgogICRwbGF5ZXJzID0gW107CgogIC8vIERhZG9zIGRvIGpvZ2Fkb3I6CiAgJHBsYXllciA9IFtdOwoKICAvLyBQZXJjb3JyZSB0b2RvcyBv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