Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Old 10-01-2006, 06:01 PM   #1 (permalink)
v7n Mentor
 
Izzmo's Avatar
 
Join Date: 11-01-03
Location: Kansas City
Posts: 1,330
iTrader: 0 / 0%
Latest Blog:
Starting p90x today

Izzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web pro
Send a message via ICQ to Izzmo Send a message via AIM to Izzmo Send a message via MSN to Izzmo Send a message via Yahoo to Izzmo
Thumbs down A simple PHP Question

Okay, so I consider myself pretty technical with PHP, enough to make a portal-based graphics forum, my own script, like DeviantArt.

So, I've ALWAYS wondered this, where do you use the '===' at? (The 3 eqal signs in a row).

I've never came across it, ever, where I've had to use it..

So, can someone help me out?

Thanks.
__________________
Izzmo
Coding Guru Extraordinaire
ZeroWeb Hosting & Design - Customizable hosting for every type of user!
Izzmo is online now  
Add Post to del.icio.us
Reply With Quote
Old 10-01-2006, 06:59 PM   #2 (permalink)
Senior Member
 
StupidScript's Avatar
 
Join Date: 09-22-06
Location: Los Angeles
Posts: 663
iTrader: 0 / 0%
Latest Blog:
None

StupidScript is just really niceStupidScript is just really niceStupidScript is just really niceStupidScript is just really niceStupidScript is just really niceStupidScript is just really niceStupidScript is just really niceStupidScript is just really niceStupidScript is just really niceStupidScript is just really niceStupidScript is just really nice
That comparison operator means "identical to".

Here's a quick cheatsheat:

ASSIGNMENT OPERATOR:
Code:
= Example: x = y; Used to SET variable x equal in every way to variable y.
COMPARISON OPERATORS:
Code:
== Example: if (x == y) Used to COMPARE variable x to variable y. If they are of the same VALUE, it matches
Code:
=== Example: if (x === y) Used to COMPARE variable x to variable y. If they are of the same VALUE and the same TYPE, it matches
Code:
!= Example: if (x != y) Used to COMPARE variable x to variable y. If they are not of the same VALUE, it matches
Code:
!== Example: if (x !== y) Used to COMPARE variable x to variable y. If they are not of the same VALUE and TYPE, it matches
I usually use the "identical" comparison operator when I am pulling an integer from a database. This is because any value greater than 0 can be interpreted as a boolean "true" value.

Code:
if (x == 1) 1 is an integer that will match if x has any value, even if x is a string.
Code:
if (x === 1) 1 is an integer that will match if x's value is 1 AND if x's type is "integer".

Last edited by StupidScript; 10-01-2006 at 07:02 PM..
StupidScript is offline  
Add Post to del.icio.us
Reply With Quote
Old 10-01-2006, 09:05 PM   #3 (permalink)
Contributing Member
 
jwalsh's Avatar
 
Join Date: 03-22-04
Location: Cleveland, OH
Posts: 264
iTrader: 0 / 0%
jwalsh is a name known to alljwalsh is a name known to alljwalsh is a name known to alljwalsh is a name known to alljwalsh is a name known to alljwalsh is a name known to alljwalsh is a name known to alljwalsh is a name known to alljwalsh is a name known to alljwalsh is a name known to alljwalsh is a name known to all
$x = "3";
$y = 3;

$x == $y will pass
$x === $y will fail because they are different types.

Now, if only PHP supported strict typing.
jwalsh is offline  
Add Post to del.icio.us
Reply With Quote
Old 10-02-2006, 05:07 AM   #4 (permalink)
Member
 
Join Date: 08-02-06
Location: Sweden
Posts: 30
iTrader: 0 / 0%
Latest Blog:
None

Litewebsite is liked by many
Send a message via Yahoo to Litewebsite
You could also do type casting for your variables.

PHP Code:
$x 1;
$y '1';
$y = (int)$y// type casting 
Now both variables are integers and will match ===.
Litewebsite is offline  
Add Post to del.icio.us
Reply With Quote
Old 10-02-2006, 12:33 PM   #5 (permalink)
v7n Mentor
 
Izzmo's Avatar
 
Join Date: 11-01-03
Location: Kansas City
Posts: 1,330
iTrader: 0 / 0%
Latest Blog:
Starting p90x today

Izzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web proIzzmo is a highly respected web pro
Send a message via ICQ to Izzmo Send a message via AIM to Izzmo Send a message via MSN to Izzmo Send a message via Yahoo to Izzmo
Ahah Thanks!

All 3 of you have helped me out greatly. Thanks soo much!

(Now... off to code ASP .. dang)
__________________
Izzmo
Coding Guru Extraordinaire
ZeroWeb Hosting & Design - Customizable hosting for every type of user!
Izzmo is online now  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP: simple question. iiz Coding Forum 2 02-12-2008 03:28 PM
Simple GIMP question! Centertainment1 Graphic Design Forum 1 12-18-2006 01:33 AM
Simple Question timmoyse Marketing Forum 11 09-16-2006 04:45 PM
Simple JavaScript question I, Brian Coding Forum 16 01-07-2005 11:27 AM
Simple FrontPage question. fosho flash Web Design Lobby 3 05-25-2004 02:41 AM


Sponsor Links
Get exposure! Contextual Links V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 05:07 PM.
© Copyright 2008 V7 Inc
Powered by vBulletin
Copyright © 2000-2009 Jelsoft Enterprises Limited.


Search Engine Optimization by vBSEO 3.3.0 ©2009, Crawlability, Inc.