Luciano Luciano - 3 months ago 9
PHP Question

Php blank lines

$i=0;
while($i<=8){
$id=$recenti['games'][0]['fellowPlayers'][$i]['summonerId'];
$teamid=$recenti['games'][0]['fellowPlayers'][$i]['teamId'];
$altri = json_decode(file_get_contents('https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/'.$id.'?api_key=my_api_key'), true);
$nome=$altri[$id]['name'];
if ($teamid===200){
echo '<div style="float:right">',$nome,'</div><br>';
}
else{
echo '<div style="float:left">',$nome,'</div><br>';
}
$i++;
}


i used php with json to retrieve data of my last match and have the names of the players with riot Api. In html this results me full of blank spaces . example:

Test1
Test2
Test3
Test4
Test5
Test6
Test7
Test8
Test9


I would like to remove the blank lines, how can i ?

Answer

You a proposal, try:

    $i=0;
    $left = array();
    $right = array();
    while($i<=8){
        $id=$recenti['games'][0]['fellowPlayers'][$i]['summonerId'];
        $teamid=$recenti['games'][0]['fellowPlayers'][$i]['teamId'];
        $altri = json_decode(file_get_contents('https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/'.$id.'?api_key=my_api_key'), true);
        $nome=$altri[$id]['name'];
        if ($teamid===200){
            array_push(right, $nome);
            echo '<div style="float:right">',$nome,'</div><br>';
        }
        else{
            array_push($left, $nome);

            echo '<div style="float:left">',$nome,'</div><br>';
        }
        $i++;
    }

    echo '<div style="float:left">';
    foreach (left as $nome) {
        echo $nome.'<br />';
    }
    echo '</div>';

    echo '<div style="float:right">';
    foreach ($right as $nome) {
        echo $nome.'<br />';
    }
    echo '</div>';

Basically push the names in two array for left and righ columns.