Jump to content

One 'if' statement works, one doesn't!


Zugzwangle

Recommended Posts

$parts[] is an array of the following:

[Event \"90m + 5s, rated\"
[site \"Main Playing Hall\" 
[Date \"2010.06.17\" 
[Round \"?\" 
[White \"Zugzwang1\" 
[black \"Jeff Morris\" 
[Result \"0-1\" 
[WhiteElo \"1189\" 
[blackElo \"1233\" 
[PlyCount \"30\" 
EventDate \"2010.06.17\" 
[EventType \"blitz\" 
[TimeControl \"60\" 

 

The first for statement below works.. the 2nd doesn't, yet $partsLocation and $correctLocation are the same value, as tested with an echo statement (echo ($partsLocation).'<br>'; echo ($correctLocation);).

<?php
$correctControl = '[Event \"90m + 5s, rated\"';
$partsControl = $parts[0];
//echo ($partsControl.'<br>');
//echo ($correctControl.'<br>');
if ($partsControl == $correctControl)
{
	echo ("Correct time control!!<br>");
}
 else 
{
echo ("Time Control is wrong!!!");
}


$correctLocation = '[site \"Room 1\"'; 
$partsLocation = $parts[1];
//echo ($partsLocation).'<br>';
//echo ($correctLocation);
if ($partsLocation == $correctLocation)
{
	echo "Correct Location";
}
else 
{
echo ("Location is wrong!!!<br>");
}
?>

OUTPUTS:

Correct time control!!
Location is wrong!!!

The first for statement works, and the 2nd doesn't.. I can't see why. Can you?

Link to comment
https://forums.phpfreaks.com/topic/205172-one-if-statement-works-one-doesnt/
Share on other sites

Please dump the $parts array using

<?php
echo '<pre>' . print_r($parts,true) . '</pre>';
?>

and post the results here.

 

Also, there could be some extraneous characters in the values that you're not seeing with your eye. Try the following "if" statemen:

<?php

if (trim($partsLocation) == trim($correctLocation))
{
	echo "Correct Location";
}
else 
{
echo ("Location is wrong!!!<br>");
}
?>

 

Ken

The output for the following:

<?php
echo '<pre>' . print_r($parts,true) . '</pre>';
?>

is

Array
(
    [0] => [Event \"90m + 5s, rated\"
    [1] => 
[site \"Room 1\"
    [2] => 
[Date \"2010.06.18\"
    [3] => 
[Round \"?\"
    [4] => 
[White \"Zugzwang1\"
    [5] => 
[black \"Jeff Morris\"
    [6] => 
[Result \"1-0\"
    [7] => 
[WhiteElo \"1543\"
    [8] => 
[blackElo \"1537\"
    [9] => 
[PlyCount \"5\"
    [10] => 
[EventDate \"2010.06.18\"
    [11] => 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.