TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   & and ` (http://www.talkphp.com/absolute-beginners/4155-a.html)

Sakakuchi 04-18-2009 12:46 PM

& 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'


Tanax 04-18-2009 12:50 PM

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.

Salathe 04-18-2009 01:25 PM

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.

Sakakuchi 04-18-2009 04:38 PM

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

allworknoplay 04-18-2009 04:48 PM

Quote:

Originally Posted by Sakakuchi (Post 23196)
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...


All times are GMT. The time now is 12:48 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0