How to compare 2 variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    How to compare 2 variables

    I seem to be stuck on comparing two variables. Everything I have tried appears to say they are equal, but the If condition returns false every time.

    Here is the problematic code
    Code:
    $cBoring    = str_pad(trim($this->r[$key]["BORING"]),5,' ',STR_PAD_LEFT);
    
    $cContainer = str_pad(trim($this->r[$key]["CONTNUMB"]),3,' ',STR_PAD_LEFT);
    
    $cKey = $this->r[$key]["JOBID"] . $cBoring . $cContainer;
    
    $rKey = trim($this->r[$key]["reckey"]);
    
    /*
    I then use this simple test to check the values of each variable */
    
    if (($rKey != $cKey) ){ 
      /* here I'm just checking to make sure they are the  */same type
    	$rtype = gettype (  $rKey );
    	$ctype = gettype (  $cKey );
    
    /*here I'm just capturing the results for my ajax reponse*/	
    $fErr =  $fErr .' r and c not the same=`'.$rKey.'`-`'.$cKey.'` rType='.$rtype.' cType='.$ctype;
    }

    here is the sample input data:
    reckey = '83217 1680'
    jobid = '83217'
    boring = '1 '
    CONTNUMB = '680'

    The result of both $cKey and $rKey are as follows:

    Type = string

    Value = (Actual output) r and c not the same=`83217 1680`-`83217 1680` - this is the actual output delimited with the ` to show there are no leading or trailing spaces.
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    #2
    Never mind. Have to be careful when looking at spaces they get condensed in the output

    A simple str_replace command showed the difference
    Code:
    		$Rval = str_replace(" ", "/", $rKey);
    		$Cval = str_replace(" ", "/", $cKey);
    and the result when the spaces were replaced with the slashes
    looked like this

    rType=83217/////1680
    cType=83217////1680

    one space missing. Well that was about 3 hours of wasted time.

    Comment

    Working...