This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.
It used to be hard to find questions about operators and other syntax tokens.¹
The main idea is to have links to existing questions on Stack Overflow, so it's easier for us to reference them, not to copy over content from …
什么是=&
(等于-号)赋值运算符在PHP中呢?
它被弃用了吗?
可能重复: PHP中的"=&"和"&="运算符是什么意思?
我在下面的代码中找到了运算符"=&",我不知道它的含义.它是什么意思,它有什么作用?
我读它的代码:
function ContentParseRoute($segments)
{
$vars = array();
//Get the active menu item
$menu =& JSite::getMenu();
$item =& $menu->getActive();
// Count route segments
$count = count($segments);
....
Run Code Online (Sandbox Code Playgroud) 我不是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']];
}
Run Code Online (Sandbox Code Playgroud)
我想了解最后一行,$db_host = &$db_hosts[$db_item['hostid']];
.
它似乎正在创建一个新变量,$db_host
并在其中放置一些东西,但我不明白&$db_hosts
.
我有点怀疑,因为据我所知,这$db_hosts
是一个空阵列.
我发现了这个和这个,但我不太确定,因为在这些链接中,运算符是"=&",并且在代码中,运算符附加到变量"=&$ db_hosts"(它有一个空格=和&之间.
既然我试图修改它并且没有取得成功,我认为最好寻求帮助......
可能重复:
参考 - 这个符号在PHP中意味着什么?
什么是&$variable
函数的含义和意义
function &SelectLimit( $sql, $nrows=-1, $offset=-1, $inputarr=false, $secs2cache=0 )
{
$rs =& $this->do_query( $sql, $offset, $nrows, $inputarr);
return $rs;
}
Run Code Online (Sandbox Code Playgroud) 请参阅Web上有关PHP Factory Pattern的示例.
在线$kind =& Vehicle::category($wheel);
,我为什么要使用&
?
代码:
<?php
class Vehicle {
function category($wheel = 0) {
if ($wheel == 2) {
return "Motor";
} elseif($wheel == 4) {
return "Car";
}
}
}
class Spec {
var $wheel = '';
function Spec($wheel) {
$this->wheel = $wheel;
}
function name() {
$wheel = $this->wheel;
return Vehicle::category($wheel);
}
function brand() {
$wheel = $this->wheel;
$kind =& Vehicle::category($wheel);
if ($kind == "Motor") {
return array('Harley','Honda');
} elseif($kind = "Car") …
Run Code Online (Sandbox Code Playgroud) 我是php和mysql的新手.我在youtube上关注phpacademy的教程.有一个部分是表单数据,但是每个遵循教程(包括我自己)的人都有未定义的索引错误.我用&
(&符号)符号修复它.但它在以下情况下做了什么?为什么将$符号放在$前面会停止错误?它和@是一样的吗?它只是抑制错误还是实际修复它?
$submit = &$_POST['submit'];
Run Code Online (Sandbox Code Playgroud)