Rakesh
Rakesh

Reputation: 301

if condition not working with same $variable in php

i have three array and all array have relation (like:Date[0] Game[0] Data[0])

Array in index format

DATE     | GAME | DATA
17-12-14 | A    | 72
17-12-14 | B    | 16
17-12-14 | C    | 78
18-12-14 | A    | 45
18-12-14 | B    | 56
18-12-14 | C    | 89

Now i want to get result like that

DATE     | GAME | DATA
17-12-14 | C    | 78
18-12-14 | A    | 45
18-12-14 | B    | 56

Here my code what i am tried

    foreach ($date as $key => $value) {
    $dateSet=($dates[$key]);
    $gameSet=($games[$key]);
    $dataSet=($datas[$key]);

    if (($dateSet >= "17-12-14" ) &&($gameSet == "A") && ($gameSet == "B") && ($gameSet == "C")){
        echo $dateSet.'-'.$gameSet.'-'.$dataSet."<br />";
    }
    }

output A blank page :(

thank in advance

Update

    if (($dateSet >= "17-12-14" ) &&(($gameSet == "A")||($gameSet == "B")||($gameSet == "C"))){
        echo $dateSet.'-'.$gameSet.'-'.$dataSet."<br />";
    } 

now output is all six rows . but i want only 17-12-14 C row and 18-12-14 A and B rows

Upvotes: 0

Views: 78

Answers (2)

Darkman
Darkman

Reputation: 333

You're if statement is incorrect. Change to

(($dateSet >= "17-12-14" ) && (($gameSet == "A") || ($gameSet == "B") || ($gameSet == "C")))

Upvotes: 1

Erik
Erik

Reputation: 3636

if (($dateSet >= "17-12-14" ) &&($gameSet == "A") && ($gameSet == "B") && ($gameSet == "C")){

You require the variable $gameSet to be equal to A AND B AND C, which is of course impossible. You'll need to change your IF statement. Possibly by using a few OR checks ->

 if (($dateSet >= "17-12-14" ) && (($gameSet == "A") || ($gameSet == "B") || ($gameSet == "C"))){

Upvotes: 0

Related Questions