Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ^ mean in PHP?

Tags:

php

I came across this line of code in an application I am revising:

substr($sometext1 ^ $sometext2, 0, 512);

What does the ^ mean?

like image 931
chicane Avatar asked Apr 27 '10 20:04

chicane


People also ask

What does mean :: in PHP?

In PHP, the double colon :: is defined as Scope Resolution Operator. It used when when we want to access constants, properties and methods defined at class level. When referring to these items outside class definition, name of class is used along with scope resolution operator.

What does 3 dots mean in PHP?

This is the so called "splat" operator. Basically that thing translates to "any number of arguments"; introduced with PHP 5.6.

What is the mean of @symbol in PHP?

Hello @kartik, The @ symbol is the error control operator ("silence" or "shut-up" operator). It makes PHP suppress any error messages (notice, warning, fatal, etc) generated by the associated expression. It works just like a unary operator, for example, it has a precedence and associativity.

Why do we use $this in PHP?

$this is a reserved keyword in PHP that refers to the calling object. It is usually the object to which the method belongs, but possibly another object if the method is called statically from the context of a secondary object. This keyword is only applicable to internal methods.


2 Answers

^ is the bitwise exclusive OR operator. For each bit in a value, it looks to see if that bit is the same in the other value; if it is the same, a 0 is output in its place, otherwise a 1 is output. For example:

  00001111
^ 01010101
  --------
  01011010
like image 97
mipadi Avatar answered Sep 22 '22 00:09

mipadi


XOR (exclusive OR):

$a ^ $b means bits that are set in $a or $b, but not both, are set.

like image 28
Mitch Dempsey Avatar answered Sep 22 '22 00:09

Mitch Dempsey