473,387 Members | 1,592 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.

Why does this value return true?

Hi All, when running this in php, it returns true.

Which doesn't make sense as 800 is smaller than

Expand|Select|Wrap|Line Numbers
  1.     if(0124 >= 0800)
  2.         {
  3.             echo "this doesnt makes sense";    
  4.         }
  5.  
  6.  
Not sure why this is the case. However getting rid of the 0 in front fixes it. But I need to keep it as I am comparing time. EG: 0124 is greater than 0800 (8am) etc.

Can someone tells me why PHP behaves this way when you prefix your number with 0?

Many thanks.
May 16 '12 #1

✓ answered by firexfighterx

If you cast them to an int you wont have this problem.

4 1829
If you cast them to an int you wont have this problem.
May 16 '12 #2
Dormilich
8,658 Expert Mod 8TB
the problem with the leading 0 is that it will cast the number to octal. i.e. 0124 is converted to 84 and 0800 to 0 (because 8 is not part of the octal system)

EG: 0124 is greater than 0800 (8am) etc.
01:24 AM is greater than 08:00 AM?

if you want to compare dates, use PHP’s date formats (e.g. the UNIX Timestamp or the DateTime classes)
May 17 '12 #3
Cheers guys. Type casting it fixed it.

@Dormilich, thanks for the explanation. Never thought hex was in the picture
May 18 '12 #4
johny10151981
1,059 1GB
along with dormilich answer you should also know that if you parse 0 leading number in javascript you will get Octal value
May 23 '12 #5

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

Similar topics

2
by: lkrubner | last post by:
My code was dying on the line below where I use method_exists: if (class_exists($nameOfClassToBeUsed)) { $object = new $nameOfClassToBeUsed(); $this->arrayOfAllTheObjectsSoFarLoaded = &...
3
by: Lasse Edsvik | last post by:
Hello one question........ why does isnumeric return true? a="" if isnumeric(a) then response.write("test") end if empty isnt numerical is it??
5
by: w i l l | last post by:
Why does this work the way it does? If someone could explain return true, and return false to me I'd greatly appreciate it. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ...
6
by: RitaG | last post by:
Hi. I have a Sub that calls a Boolean Function and exits the Sub if the Return value is False. The problem is it's exiting the Sub even if the Return value is True. Here's my code. Private...
3
by: Alpha | last post by:
Hi, I have a window C# application. I update the dataset when user finished entering in a text box. But when I want to update the database when OK is pressed, the...
3
by: ATS | last post by:
PRB - UseShellExecute option does not return STD-ERR Please help, I'm using the Process class to start an external process that "may" fail, for all kinds of reasons, but in particular, it may...
5
by: Dmitriy Lapshin [C# / .NET MVP] | last post by:
Hi all, I think the VB .NET compiler should at least issue a warning when a function does not return value. C# and C++ compilers treat this situation as an error and I believe this is the right...
4
by: Vikas Rana | last post by:
Hi all, I am a bit confused about the method java.sql.DatabaseMetaData.nullsAreSortedHigh(). What exactly does this return? If this returns true, are nulls considered as the highest value? Or...
2
by: BerkshireGuy | last post by:
I have the following union query that works great, but I want to alter the query to only return True (-1) for the TEST column. Currently the test column DOES return 0 or -1. I just want the -1....
33
by: zamaam0728 | last post by:
I am at the end of my first semester of C++, and I'm not sure what I should do to make this program meet the requested specifications. The assignment is as follows: Write a function called...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.