Roi Roi - 3 months ago 13
PHP Question

find string by compare to values

I'm using a web-service to get products details.
I want to compare two values and, if they are equal, to print "FOUND".
For some reason I get nothing.

The problem is with the last IF:

if ($product['ProductId'] == $paxServices['ProductId'])


This is the output:

paxProID:332 ?? pro:-1
paxProID:332 ?? pro:332
paxProID:332 ?? pro:6
paxProID:6 ?? pro:-1
paxProID:6 ?? pro:332
paxProID:6 ?? pro:6


As you can see, there are 2 equal numbers: 332 (second row) and 6 (the last row)

The PHP code:

foreach ($pnrPaxsXml AS $i => $pax)
{
if ($pax['ID'] == $_GET['paxID'])
{
foreach ($pax->Order AS $i => $paxServices)
{
foreach ($pnrProductsXml AS $i => $product)
{
echo "paxProID:".$paxServices['ProductId']."<>pro:".$product['ProductId']."<br />" ;

if ($product['ProductId'] == $paxServices['ProductId'])
echo "FOUND<br />";
}
}
}
}

Answer

change the code in this way

if (intval($product['ProductId']) ===  intval($paxServices['ProductId']))
                echo "FOUND<br />";
        }