TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-18-2009, 12:46 PM   #1 (permalink)
The Contributor
 
Sakakuchi's Avatar
 
Join Date: Feb 2009
Posts: 64
Thanks: 1
Sakakuchi is on a distinguished road
Default & and `

Hi there,

I was actually wondering why - we also use && instead of & when combining to expressions like:


PHP Code:
if($a == $b && $b == $c

So I made a simple script to check out what an simple & would do:

PHP Code:
<?php 

$a 
'a' 'b';

echo 
$a;

 
?>
What the script gives out is the following:

´

Could someone explain why I get that funny result? And when to use a single &

thx 4 reading :)


Ou yeah and a function with a single & seems to work too:
PHP Code:
if(== == 2) echo 'funzt'
Sakakuchi is offline  
Reply With Quote
Old 04-18-2009, 12:50 PM   #2 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

I don't know why it gives you that.
But I know the way to accomplish what I think you want, which is replacing & with a dot, that way you get "ab" echoed.

Also, another thing why it's 2 & and not 1 & is probably because you can use it with other expressions, like =& which would make a reference to the value of the other variable.
__________________
Tanax is offline  
Reply With Quote
Old 04-18-2009, 01:25 PM   #3 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

The & is a 'bitwise and' operator and is used in doing arithmetic on binary. For the example that you gave 'a' is binary 01100001 and 'b' is binary 01100010. The & means to set the result's bits to 1 where it is set in both, and to 0 otherwise. So the result is 01100000. Now, the echo statement converts the result to a string and the ASCII character for 01100000 (decimal number 96) is the backtick (`) character.
Salathe is offline  
Reply With Quote
Old 04-18-2009, 04:38 PM   #4 (permalink)
The Contributor
 
Sakakuchi's Avatar
 
Join Date: Feb 2009
Posts: 64
Thanks: 1
Sakakuchi is on a distinguished road
Default

wow, thats some cool stuff. Is there something like a pocket-salathe for my desktop - cause you seem to know everything :)

Thx to both of you
Sakakuchi is offline  
Reply With Quote
Old 04-18-2009, 04:48 PM   #5 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Sakakuchi View Post
wow, thats some cool stuff. Is there something like a pocket-salathe for my desktop - cause you seem to know everything :)

Thx to both of you
I agree...it would be cool to have a widget...
allworknoplay is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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


All times are GMT. The time now is 03:50 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design