IT Community - Software Programming, Web Development and Technical Support

I want the explanation for the below example code..

This is a discussion on I want the explanation for the below example code.. within the PHP Programming forums, part of the Web Development category; "consider the following example $x = true and false; print_r($x); //outputs bool(true) why does the ""and&...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-26-2007, 03:38 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Question I want the explanation for the below example code..

"consider the following example
$x = true and false;
print_r($x); //outputs bool(true)
why does the ""and"" operator act like an ""OR "" operator"
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-26-2007, 03:39 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: I want the explanation for the below example code..

$y = ($x = true and false);
var_dump($x); //outputs bool(true)
var_dump($y); //outputs bool(false)

This is a case of mistaken operator precedence. In this example, the assignment operator (=) has higher precedence than the 'and' operator, so $x is assigned the value true. The second example clears things up a bit. After the first assignment to $x, the return value (true) is anded with false, yielding false, which is assigned to $y.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


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

vB 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
Register dll or ocx using through code in C# oxygen C# Programming 4 08-06-2008 12:58 AM
C- Tricky Question & answers With explanation vijayanand C and C++ Programming 46 01-03-2008 11:00 PM
optimizing the code vijayanand PHP Programming 0 07-17-2007 12:25 AM
JAVA code from PHP ramkumaraol PHP Programming 2 07-16-2007 11:54 PM
COM - The Short Explanation Karpagarajan C and C++ Programming 0 04-10-2007 09:52 AM


All times are GMT -7. The time now is 03:42 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0