How does the bitwise operator XOR ('^') work?

I'm a little confused when I see the output of following code: $x = "a"; $y = "b"; $x ^= $y; $y ^= $x; $x ^= $y; echo $x; //Got b echo $y; //Got a How does the operator ^ work here? This looks like swapping a value using XOR. Though I am not sure about the strings in PHP (normally you use it for ints or something). For a truth table of XOR you can look here. The interesting thing abou

按位运算符XOR('^')如何工作?

当我看到以下代码的输出时,我有点困惑: $x = "a"; $y = "b"; $x ^= $y; $y ^= $x; $x ^= $y; echo $x; //Got b echo $y; //Got a 如何操作^在这里工作? 这看起来像使用XOR交换一个值。 虽然我不确定PHP中的字符串(通常用于整数或某物)。 对于XOR的真值表,你可以看看这里。 关于XOR的有趣之处在于它是可逆的:XOR B XOR B == A ...不适用于AND或OR 。 由于这个事实,它可以用于你的例子中交换两个值: $x ^= $y; $

What does $k => $v in foreach($ex as $k=>$v) mean?

Possible Duplicates: What does “=>” mean in PHP? What does $k => $v mean? It means that for every key-value pair in the traversable variable $ex , the key gets assigned to $k and value to $v . In other words: $ex = array("1" => "one","2" => "two", "3" => "three"); foreach($ex as $k=>$v) { echo "$k : $v n"; } outputs: 1 : one 2 : two 3 : three You're looping ove

foreach中的$ k => $ v($ ex为$ k => $ v)是什么意思?

可能重复: “=>”在PHP中意味着什么? $k => $v是什么意思? 这意味着对于遍历变量$ex中的每个键值对,键被分配到$k并且值为$v 。 换一种说法: $ex = array("1" => "one","2" => "two", "3" => "three"); foreach($ex as $k=>$v) { echo "$k : $v n"; } 输出: 1 : one 2 : two 3 : three 你正在循环一个数组。 数组有键(数字,或者当你有一个关联数组时可以是字符串)以及'属于'这些

Use of => in PHP

What does this mean in PHP and when is the time to use it? => Another example. foreach ($parent as $task_id => $todo) To elaborate a bit on what has already been said. Assuming that you know about arrays in PHP. Which is really a way of grouping a "list" of items under the same variable given a certain index - normally a numeric integer index starting from 0. Say we want

在PHP中使用=>

这在PHP中意味着什么以及何时使用它? => 另一个例子。 foreach ($parent as $task_id => $todo) 详细阐述一下已经说过的话。 假设你知道PHP中的数组。 在给定某个索引的情况下,这实际上是将同一变量下的项目“列表”分组的一种方式 - 通常是从0开始的数字整数索引。假设我们要编制一个索引英语术语列表,也就是说, Zero One Two Three Four Five 使用数组在PHP中表示可以这样做: $numbers = array("Zero", "O

What does "=>" mean in PHP?

What does the => operator mean in the following code? foreach ($user_list as $user => $pass) The code is a comment at PHP.net. The user does not specify the value of $user_list , $user or $pass. I normally see that => means equal or greater than. However, I am not sure about its purpose here because it is not assigned. I read the code as process a list of users in integers suc

“=>”在PHP中意味着什么?

以下代码中=>运算符的含义是什么? foreach ($user_list as $user => $pass) 该代码是在PHP.net上的注释。 用户没有指定$user_list , $user或$ pass的值。 我通常看到=>表示等于或大于。 但是,我不确定它的用途,因为它没有被分配。 我读了代码 处理整数中的用户列表 使每个用户的值等于或大于密码 以上对我没有意义。 =>是关联数组的分隔符。 在该foreach循环的上下文中,它将数组的键分配给$use

>" mean/refer to in PHP?

This question already has an answer here: Reference — What does this symbol mean in PHP? 18 answers -> accesses a member of an object. So $wp_query->max_num_pages is accessing the field max_num_pages in the object $wp_query . It can be used to access either a method or a field belonging to an object, and if you're familiar with C++ or Java, it's equivalent to myObject.myField

>“意味着/指在PHP中?

这个问题在这里已经有了答案: 参考 - 这个符号在PHP中的含义是什么? 18个答案 ->访问一个对象的成员。 所以$wp_query->max_num_pages正在访问场max_num_pages的对象$wp_query 。 它可以用于访问属于对象的方法或字段,并且如果您熟悉C ++或Java,则它等同于myObject.myField 首先你应该了解以下内容。 在PHP和许多其他语言中,我们有以下类型的实体: 变量 数组 对象 ->允许您访问对象内的方法或值

What does the PHP syntax $var1

以下语法的解释是什么? $var1->$var2 // Note the second $ $var1 is an object. $var2 is (possibly) the name of a variable inside $var1 . If $var2="test"; this is evaluated to: $var1->test; You can do this with all sorts of things: $test = array(); $name="test"; print_r($$name); // Prints array(); $test = new stdClass; $test->hello = "hi"; $name2="hello"; echo $test->$

PHP语法$ var1是什么?

以下语法的解释是什么? $var1->$var2 // Note the second $ $var1是一个对象。 $var2 (可能)是$var1的一个变量的名称。 如果$var2="test"; 这被评估为: $var1->test; 你可以用各种各样的东西做到这一点: $test = array(); $name="test"; print_r($$name); // Prints array(); $test = new stdClass; $test->hello = "hi"; $name2="hello"; echo $test->$name2; // Echos hi 你甚至可以变得

Where do we use the object operator "

有哪些不同的方式,我们可以使用对象运营商->在PHP? PHP has two object operators. The first, -> , is used when you want to call a method on an instance or access an instance property. The second, :: , is used when you want to call a static method, access a static variable, or call a parent class's version of a method within a child class. 访问实例化类的方法或属性时class SimpleClass {

我们在哪里使用对象操作符“

有哪些不同的方式,我们可以使用对象运营商->在PHP? PHP有两个对象操作符。 第一个->用于在实例上调用方法或访问实例属性。 第二个::是在你想要调用一个static方法,访问一个static变量,或者调用一个子类中的父类的方法版本时使用的。 访问实例化类的方法或属性时class SimpleClass { // property declaration public $var = 'a default value'; // method declaration public function displayVar

What does a \ (backslash) do in PHP (5.3+)?

What does a do in PHP? For example, CSRF4PHP has FALSE , session_id , and Exception : public function __construct($timeout=300, $acceptGet=FALSE){ $this->timeout = $timeout; if (session_id()) { $this->acceptGet = (bool) $acceptGet; } else { throw new Exception('Could not find session id', 1); } } (backslash) is the namespace separator in PHP 5.3. A b

PHP(5.3+)中的\(反斜杠)是做什么的?

在PHP中做什么? 例如,CSRF4PHP具有FALSE , session_id和Exception : public function __construct($timeout=300, $acceptGet=FALSE){ $this->timeout = $timeout; if (session_id()) { $this->acceptGet = (bool) $acceptGet; } else { throw new Exception('Could not find session id', 1); } } (反斜杠)是PHP 5.3中的命名空间分隔符。 在函数开始之前的代表全局命名空间

what does it mean?

I just saw the use of a backslash in a reference to a PHP object and was curious about it (I have never seen this before). What does it mean? $mail = new SendGridMail(); If you're curious, here's SendGrid's documentation. It's because they're using PHP namespaces. Namespaces are new as of PHP 5.3. It's PHP's namespace operator: http://php.net/manual/en/language

这是什么意思?

我刚刚在一个PHP对象的引用中看到了反斜杠的使用,并且对它很好奇(我以前从未见过)。 这是什么意思? $mail = new SendGridMail(); 如果你很好奇,这里是SendGrid的文档。 这是因为他们正在使用PHP命名空间。 命名空间是PHP 5.3的新增功能。 它是PHP的命名空间操作符:http://php.net/manual/en/language.namespaces.php。 不要问为什么它是反斜杠。 这是(imho)他们可能做出的最愚蠢的选择,他们的决定基于一种高

Unexpected T

I moved an application from an Ubuntu 11.04 (Natty Narwhal) Server to a Red Hat Enterprise Linux (RHEL) server over the weekend. My error log is full of the PHP errors in the subject line referencing the following function: function wfTalkHereArticleFromTitle( &$title, &$article ) { global $wgRequest, $wgTalkHereNamespaces; if (isset($title->noTalkHere)) return true;

意外的T

我周末将应用程序从Ubuntu 11.04(Natty Narwhal)服务器移至红帽企业Linux(RHEL)服务器。 我的错误日志充满了引用以下函数的主题行中的PHP错误: function wfTalkHereArticleFromTitle( &$title, &$article ) { global $wgRequest, $wgTalkHereNamespaces; if (isset($title->noTalkHere)) return true; //Stop recursion $action = $wgRequest->getVal( 'action' ); $oldid