473,473 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to compare 2 variables

Claus Mygind
571 Contributor
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
1 1324
Claus Mygind
571 Contributor
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.