user1893145
user1893145

Reputation: 45

foreach use them multiple times

http://pastebin.com/MFCQzJQ8

I have this code and I am trying to get it to output the result

echo $attack.' Attacks Have Been Stopped On Server '.$id.'<br>';

different every time but I can only get the server id or the attack to change but I need both to change and output on a new line ever time.

http://gyazo.com/f38c20ecef5af72dcc534be88101f8a2

    <?php
    if (isset($_POST['stop']))
    {
        $ids = $_POST['id'];
        $urls = $_POST['url'];
        $attacks = $_POST['attack'];
        foreach($urls as $url);
        foreach($attacks as $attack);
        foreach($ids as $id);


            echo '<div class="nNote nSuccess hideit"><p><strong>SUCCESS: </strong><br>';

            foreach($ids as $id){
            if($attack == "NONE"){$attack = "No";}
            echo $attack.' Attacks Have Been Stopped On Server '.$id.'<br>';
            }
            echo '</p></div>';
    }
    ?>

Upvotes: 0

Views: 121

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324630

You can combine the arrays into one and iterate over it:

foreach(array_map(null,$ids,$urls,$attacks) as list($id,$url,$attack)) {
    // code body here
}

Upvotes: 1

Related Questions