What does "&" mean here in PHP?

Consider this PHP code: call_user_func(array(&$this, 'method_name'), $args); I know it means pass-by-reference when defining functions, but is it when calling a function? From the Passing By Reference docs page: You can pass a variable by reference to a function so the function can modify the variable. The syntax is as follows: <?php function foo(&$var) { $var++; } $a=5; f

PHP中的“&”是什么意思?

考虑这个PHP代码: call_user_func(array(&$this, 'method_name'), $args); 我知道这意味着在定义函数时传递引用,但是在调用函数时呢? 从传递参考文档页面: 您可以通过引用函数来传递变量,以便函数可以修改该变量。 语法如下: <?php function foo(&$var) { $var++; } $a=5; foo($a); // $a is 6 here ?> ...在最近的PHP版本中,当您在foo(&$ a)中使用&时,您会收到一条警告,指出“通过引用

Difference between & and && in PHP

I am confused with & and && . I have two PHP books. One says that they are same, but the another says they are different. I thought they are same as well. Aren't they same? & is bitwise AND. See Bitwise Operators. Assuming you do 14 & 7 : 14 = 1110 7 = 0111 --------- 14 & 7 = 0110 = 6 && is logical AND. See Logical Operators. Consider

PHP中&和&&的区别

我对&和&&感到困惑。 我有两本PHP书。 一个说他们是一样的,但另一个说他们是不同的。 我认为它们也是一样的。 他们不一样吗? &按位与。 请参阅按位运算符。 假设你做14 & 7 : 14 = 1110 7 = 0111 --------- 14 & 7 = 0110 = 6 &&是逻辑与。 请参阅逻辑运算符。 考虑这个真值表: $a $b $a && $b false false false false true false tr

PHP "&" operator

I'm not a PHP programmer (but know other languages), and I'm trying to understand a web page that was done in PHP (5.1.6) in order to do some changes. The page has the following code (simplified): $db_hosts = array(); $sql = 'SELECT h.hostid, h.host FROM hosts h '; $db_items = DBselect($sql); while($db_item = DBfetch($db_items)){ $name = $db_item['host']; $db_host = &$db_

PHP“&”运算符

我不是一个PHP程序员(但知道其他语言),并且我试图了解一个在PHP(5.1.6)中完成的网页,以便做一些更改。 该页面具有以下代码(简化): $db_hosts = array(); $sql = 'SELECT h.hostid, h.host FROM hosts h '; $db_items = DBselect($sql); while($db_item = DBfetch($db_items)){ $name = $db_item['host']; $db_host = &$db_hosts[$db_item['hostid']]; } 我试图理解最后一行, $db_host = &$db_ho

Understanding PHP & (ampersand, bitwise and) operator

I often use ($var & 1) in my code, which returns true if $var is an odd number and false if it's an even number. But what does "&" actually do? & is binary and . If you have a binary value, and you and with another binary value, then the result will be the bitwise and of the two. An example: 01101010 & 01011001 = 01001000 The rightmost bit is either a 1 (an

了解PHP&(&符号,按位和)运算符

我经常在代码中使用($var & 1) ,如果$var是一个奇数,则返回true,如果是偶数,则返回false。 但是“&”实际上做了什么? &是二进制and 。 如果你有一个二进制值,你and另一个二进制值,那么结果将是按位and两个。 一个例子: 01101010 & 01011001 = 01001000 最右边的位是1(在这种情况下,数字是奇数),或者是0,在这种情况下,数字是偶数。 如果您& 1的数字,你只能看至少显著位,而如果检查的数量

What does it mean to start a PHP function with an ampersand?

I'm using the Facebook library with this code in it: class FacebookRestClient { ... public function &users_hasAppPermission($ext_perm, $uid=null) { return $this->call_method('facebook.users.hasAppPermission', array('ext_perm' => $ext_perm, 'uid' => $uid)); } ... } What does the & at the beginning of the function definition mean, and how do I go abou

用&符号启动PHP函数是什么意思?

我在这个代码中使用了Facebook库: class FacebookRestClient { ... public function &users_hasAppPermission($ext_perm, $uid=null) { return $this->call_method('facebook.users.hasAppPermission', array('ext_perm' => $ext_perm, 'uid' => $uid)); } ... } 在函数定义的开头是什么意思,以及如何去使用这样的库(在一个简单的例子中) 函数名称之前的&符号表示该函数将返回对

Using a foreach variable in a Laravel view

My MySQL table looks like this (the relevant part): student_id (int) | engmins(int) | totalmins(int) | created_at (datetime) 1 | 50 | 100 | 2017-12-15 00:00:00 1 | 20 | 45 | 2017-12-15 00:00:00 I have the following code: $students = StudentDetails::with('student','studentschool','classactivity') ->where('class'

在Laravel视图中使用foreach变量

我的MySQL表看起来像这样(相关部分): student_id (int) | engmins(int) | totalmins(int) | created_at (datetime) 1 | 50 | 100 | 2017-12-15 00:00:00 1 | 20 | 45 | 2017-12-15 00:00:00 我有以下代码: $students = StudentDetails::with('student','studentschool','classactivity') ->where('class', 1) ->orderBy('stu

How does PHP 'foreach' actually work?

Let me prefix this by saying that I know what foreach is, does and how to use it. This question concerns how it works under the bonnet, and I don't want any answers along the lines of "this is how you loop an array with foreach ". For a long time I assumed that foreach worked with the array itself. Then I found many references to the fact that it works with a copy of the array,

PHP'foreach'如何实际工作?

让我以此为前缀说我知道什么是foreach ,是否以及如何使用它。 这个问题涉及它在引擎盖下的工作方式,我不希望按照“这是用foreach循环数组”的方式做出任何答案。 很长一段时间,我认为foreach与数组本身一起工作。 然后,我发现它提供了许多与数组副本一起工作的事实,并且我认为这是故事的结尾。 但是我最近就这个问题进行了讨论,经过一些实验后发现这实际上并不是100%真实的。 让我表明我的意思。 对于以下测试用例

Pattern for Wrapping Shell Commands in a Class

Despite its inadvisability, using PHP's shell commands to interact with non-php system commands remains a common way of quickly achieving certain results in web applications. Has anyone abstracted out the common use cases into a class library (something in Zend maybe?) that offers a more sane/common way of handling this? Every time I encounter (or have to produce) this kind of code it'

用于在类中封装Shell命令的模式

尽管不太明智,但使用PHP的shell命令与非php系统命令交互仍然是在Web应用程序中快速获得特定结果的常用方法。 有没有人将常见用例抽象成一个类库(Zend中的某些东西可能?),它提供了一种更加理智/常见的处理方式? 每当我遇到(或必须出示)这种代码时,它都是一堆程序化的意大利面条,一遍又一遍地复制粘贴。 我想知道是否(希望)PHP社区提出了一种更好的方式来处理在您的web / php应用程序中使用命令行应用程序。 执

Printing JSON with PHP

I'm building a PHP script that feeds JSON data to another script. My script builds data into a large associative array, and then outputs the data using json_encode . Here is an example script: $data = array('a' => 'apple', 'b' => 'banana', 'c' => 'catnip'); header('Content-type: text/javascript'); echo json_encode($data); The above code yields the following output: {"a":"apple",

用PHP打印JSON

我正在构建一个将JSON数据提供给另一个脚本的PHP脚本。 我的脚本将数据构建到一个大的关联数组中,然后使用json_encode输出数据。 这是一个示例脚本: $data = array('a' => 'apple', 'b' => 'banana', 'c' => 'catnip'); header('Content-type: text/javascript'); echo json_encode($data); 上面的代码产生以下输出: {"a":"apple","b":"banana","c":"catnip"} 如果你有少量的数据,这很好,但我更喜欢这些方面

How to build a RESTful API?

The issue is this: I have a web application that runs on a PHP server. I'd like to build a REST api for it. I did some research and I figured out that REST api uses HTTP methods (GET, POST...) for certain URI's with an authentication key (not necessarily) and the information is presented back as a HTTP response with the info as XML or JSON (I'd rather JSON). My question is: How

如何构建RESTful API?

问题是这样的:我有一个运行在PHP服务器上的Web应用程序。 我想为它构建一个REST API。 我做了一些研究,我发现REST api使用HTTP方法(GET,POST ...)为某些URI提供了一个身份验证密钥(不一定),并且信息以HTTP或XML响应形式返回, (我宁愿JSON)。 我的问题是: 作为应用程序的开发人员,我如何构建这些URI? 我需要在该URI编写一个PHP代码吗? 如何构建JSON对象以作为响应返回? 这是一个简单的php中的简单例