-1
$first = 'test - yes';
$second = 'yes';
$third = str_replace("test -", "", $first);

if ($second == $third) {
    echo 'yee';
    echo '<br>';
}
echo $first;
echo '<br>';
echo $second;
echo '<br>';
echo $third;

I have 3 variables. First variable has str - test - yes, second - yes and third is replaced with first with removed "test -"

So when i broughted all 3 variables i had this result "test - yes; yes; yes;" Second and third variable are the same, and when i check if ($second == $third) { echo 'yee'; } it doesnt echo it; Why

Andreas
  • 23,610
  • 6
  • 30
  • 62
Top World
  • 93
  • 10

1 Answers1

1

$first = 'test - yes';
$second = 'yes';
$third = str_replace("test -", "", $first);

After this $second and $third are not exactly equal. I mean the $third variable contains an extra space before yes.

Another thing is you are not comparing strings this way. You can compare strings by either === or strcmp($second,$third)==0. Check String comparison using == vs. strcmp stackoverflow answer for more details on this.

Pradeep Singh
  • 432
  • 5
  • 11