473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to compare 2 variables

Claus Mygind
571 512MB
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
Expand|Select|Wrap|Line Numbers
  1. $cBoring    = str_pad(trim($this->r[$key]["BORING"]),5,' ',STR_PAD_LEFT);
  2.  
  3. $cContainer = str_pad(trim($this->r[$key]["CONTNUMB"]),3,' ',STR_PAD_LEFT);
  4.  
  5. $cKey = $this->r[$key]["JOBID"] . $cBoring . $cContainer;
  6.  
  7. $rKey = trim($this->r[$key]["reckey"]);
  8.  
  9. /*
  10. I then use this simple test to check the values of each variable */
  11.  
  12. if (($rKey != $cKey) ){ 
  13.   /* here I'm just checking to make sure they are the  */same type
  14.     $rtype = gettype (  $rKey );
  15.     $ctype = gettype (  $cKey );
  16.  
  17. /*here I'm just capturing the results for my ajax reponse*/    
  18. $fErr =  $fErr .' r and c not the same=`'.$rKey.'`-`'.$cKey.'` rType='.$rtype.' cType='.$ctype;
  19. }
  20.  
  21.  

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.
May 27 '15 #1

✓ answered by Claus Mygind

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

A simple str_replace command showed the difference
Expand|Select|Wrap|Line Numbers
  1.         $Rval = str_replace(" ", "/", $rKey);
  2.         $Cval = str_replace(" ", "/", $cKey);
  3.  
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.

1 1323
Claus Mygind
571 512MB
Never mind. Have to be careful when looking at spaces they get condensed in the output

A simple str_replace command showed the difference
Expand|Select|Wrap|Line Numbers
  1.         $Rval = str_replace(" ", "/", $rKey);
  2.         $Cval = str_replace(" ", "/", $cKey);
  3.  
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.
May 27 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Peter | last post by:
Hi, I was wondering how do you compare variables that contain text strings in ASP. When I use the following If.. Then statement: If Rs("StyleNo") <> arrStyleNo(aCount) Then
3
by: Peter | last post by:
Hi, I was wondering how do you compare variables that contain text strings in ASP. When I use the following If.. Then statement: If Rs("StyleNo") <> arrStyleNo(aCount) Then
122
by: Einar | last post by:
Hi, I wonder if there is a nice bit twiddling hack to compare a large number of variables? If you first store them in an array, you can do: for (i = 0; i < n; i++) { if (array != value) {...
1
by: bengamin | last post by:
Hi, I declare two ArrayList variables.How can I compare if the two ArrayList are Value Equal. Thanks! Ben
3
by: John C Kirk | last post by:
One odd thing I've come across - if you declare a private variable in a class, it is exposed to other instances of that same class. To replicate this behaviour, create a class like this: ...
4
by: Mika M | last post by:
I need to compare two DateTime variables named as t1 and t2 using VB.NET 2003. If t1 is any earlier time as t2, only then program should do something like... If (t1 < t2) Then...
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
0
by: Harch84 | last post by:
Hi guys need some serious help I have a PostgreSQL database full of bus routes and bus stops. I am drawing them out using perl and manipulating the data. What I need to be able to do is to compare...
6
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I am trying to compare just the time portion of two variables that are of date time part. For example I have dtdate1= 2/2/07 10:00:00 dtdate2=3/4/07 9:00:00 so for the comparision I would...
26
by: neha_chhatre | last post by:
can anybody tell me how to compare two float values say for example t and check are two variables declared float how to compare t and check please help me as soon as possible
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.