Zajev
Zajev

Reputation: 31

Variables comparison php (strcmp), equality fails

I have function

if ((isset($_REQUEST['onlinca']) && $_REQUEST['onlinca'] == true)) {
    $resultintca = mysqli_query($maincon, "SELECT * FROM Exten");
    while ($row = mysqli_fetch_assoc($resultintca)) {
        $indexintca = $row['Index'];
        if (($indexintca !== $v[6])) {
            echo "notEqual";
            print_r ($indexintca);
            print_r ($v[6]);
            echo "<br>";
        }
    }
}

It outputs that

notEqual301304
notEqual302304
notEqual303304
notEqual304304
notEqual305304
notEqual306304
notEqual307304

And so on,but Equal304304 does not have to be printed as the variables are identical. I also tried to do that using strcmp but the output is the same.

Upvotes: 1

Views: 379

Answers (1)

John Conde
John Conde

Reputation: 219884

!== is a strict comparison operator that compares both value and type. So the odds are $indexintca and $v[6] are not the same data type. ($indexintca is probably a string and $v[6] an integer). So change !== to != so you only compare values:

if (($indexintca != $v[6])) {

Upvotes: 4

Related Questions