我正在做一个项目,根据具体情况,我需要将一些输出数据组合成一个变量。
*$array包含不同的用户信息

$array[]= array(
    'ts3_uuid' => $value['client_unique_identifier'],
    'channel_name' => $value['client_unique_identifier'],
    'steam_id' => $steam_id,
    'ts3_clid' => $value['clid'],
    'channel_id' => $value['cid'],
    'steam_name' => htmlspecialchars($steam_name),
    'csgo_rank' => $csgo_rank,
    'steam_status' => $steam_official_status,
    'last_steam_connection' => $timestamp,
    'steam_vac_status' => $result_steam_ban,
    'csgo_played_time' => $total_tiempo_jugado,
    'csgo_hs_porcentage' => $hs_porcent,
    'csgo_kdr' => $kdr
    );
foreach ($array as $data) {
    $channel_description = $data['steam_name'];
}

这就是我心中的结构…
if (the channel_id of different users are EQUAL){
combine their $data['steam_name'] into the $channel_description variable and
then, for example, echo it.
}

我希望你能帮助我:

最佳答案

使用一个helper数组和函数查找相同的channel_id并存储它的steam_name!在php数组中,调用同一索引不是创建新数组!所以尝试将channel_id设置为索引键。

$result = findSameChannelId($array);

foreach($result as $data) {
    echo $data["channel_description"]."<br>";
}

function findSameChannelId($array) {
    foreach ($array as $key => $value) {
        if(!isset($channel[$value["channel_id"]])) {
            $channel[$value["channel_id"]] = array("channel_description"=>"");
        }
        $channel[$value["channel_id"]]['channel_description'] .= $value["steam_name"];
    }
    return $channel;
}

10-04 12:41