Solved

Explain php if statment

Posted on 2010-08-31
8
307 Views
Last Modified: 2012-05-10
Can someone please explain in detail what these if statements are doing?

What does the three === signs to in the first one, and What does the single & in the second mean?

thanks


$aProfile = getProfileInfo($iId);
    if($aProfile === false)
        return false;

    if(!((int)$aProfile['Role'] & $iRole))
        return false;

Open in new window

0
Comment
Question by:whatshakin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 167 total points
ID: 33569135
=== will not only check the "value", but also the data type.

while ("1" == 1) will return true, ("1" === 1 ) will return false
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33569144
0
 
LVL 5

Expert Comment

by:UrbanTwitch
ID: 33569225
Whoa, thanks angelll! Didn't know that :P
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Assisted Solution

by:Tiller79188231
Tiller79188231 earned 167 total points
ID: 33569247
$aProfile = getProfileInfo($iId);

"==" will parse an integer to a string, and string to integer and compare, ignoring data types
"===" will keep datatype and compare the values

    if($aProfile === false)
        return false;


the "&" is comparing two clauses to the first argument, so it's saying
if there isn't an integer value for $aProfile['Role'] and $iRole is false then return false

    if(!((int)$aProfile['Role'] & $iRole))
        return false;
0
 

Author Comment

by:whatshakin
ID: 33569520
So the data types would be either and integer, string or something else?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33569531
see this page to know which data types PHP offers:
http://www.php.net/manual/en/language.types.intro.php
0
 
LVL 2

Expert Comment

by:Tiller79188231
ID: 33569536
yes... any of the available data types in php... the "==" will try to convert one to the other to see if the resulting values match .. and "===" will determine if the data types and value for that data type matches
0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 166 total points
ID: 33571977
The conversion of integers into strings and vice versa is called "type juggling" and PHP is a loosely typed language.  You will find this to be of considerable significance if you try to use a string for an array index.  PHP will use the non-numeric strings as-is but will convert the numeric strings into integers.  However if you add alphabetic strings to numbers you will get a different kind of result.  It's not "wrong" to do it this way, it just creates some things about the language that drive computer scientists nuts.

When you REALLY CARE about the data type, use the triple-equal notation.  Otherwise, you can use the double-equal in almost every circumstance with good results.

A good book for getting a foundation in PHP is available from SitePoint:
http://www.sitepoint.com/books/phpmysql4/

Best regards, ~Ray
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
if (is_singular not working 5 39
PHP: Filling Out/Creating a PDF 29 107
Get data from two MySQL tables 6 27
PHP substring 2 13
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question