Ampersand before a variable in foreach php

I have seen an ampersand symbol before a variable in foreach. I know the ampersand is used for fetching the variable address which is defined earlier. I have seen a code like this: <?php $arr = array(1, 2, 3, 4); foreach ($arr as &$value) { $value = $value * 2; } // $arr is now array(2, 4, 6, 8) unset($value); // break the reference with the last element ?> I just need to kno

在foreach中的一个变量之前的&符号

我在foreach中的一个变量前看到了一个&符号。 我知道&符号用于获取前面定义的变量地址。 我看到过这样的代码: <?php $arr = array(1, 2, 3, 4); foreach ($arr as &$value) { $value = $value * 2; } // $arr is now array(2, 4, 6, 8) unset($value); // break the reference with the last element ?> 我只需要知道$ value之前的用法。 我没有看到之前声明的任何变量来获取变量地址。 请帮助我为什

Reference — What does this symbol mean in PHP?

What is this? 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. Why is this? 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 r

参考 - 这个符号在PHP中的含义是什么?

这是什么? 这是一个关于PHP中语法问题的集合。 这也是一个社区Wiki,所以每个人都被邀请参与维护这个列表。 为什么是这样? 过去很难找到关于运算符和其他语法令牌的问题 主要想法是链接到堆栈溢出的现有问题,所以我们更容易引用它们,而不是复制PHP手册中的内容。 ¹注意:自2013年1月以来,Stack Overflow确实支持特殊字符。 只需通过引号括住搜索词,例如[php] "==" vs "===" 我应该在这

Can a class instantiate another class? (PHP)

I tried this and I get an error when I try to instantiate class "first" inside of class "second". The commented sections inside of class "second" cause errors. class first { public $a; function __construct() { $this->a = 'a'; } } class second { //$fst = new first(); //public showfirst() { //$firsta = $this->first->a;

一个类可以实例化另一个类吗? (PHP)

我尝试了这一点,当我尝试在类“second”中实例化类“first”时出现错误。 类“second”中的注释部分会导致错误。 class first { public $a; function __construct() { $this->a = 'a'; } } class second { //$fst = new first(); //public showfirst() { //$firsta = $this->first->a; // echo "Here is first $a: " . $firsta; //} } 编辑: 这会导致服务器错误,即

{ } mark in echo "{$e

I read about this Article I wondering about this part: try { //First try getting our user numero uno $user = new User(1); //Then, let's try to get the exception $user2 = new User('not numeric'); } catch( Exception $e ) { echo "Donkey Kong has caught an exception: {$e->getMessage()}"; } why {$e->getMessage()} must be covered in bracket? Is there any link explanation

{}标记回显“{$ e

我读过关于这篇文章的内容,我想知道这部分内容: try { //First try getting our user numero uno $user = new User(1); //Then, let's try to get the exception $user2 = new User('not numeric'); } catch( Exception $e ) { echo "Donkey Kong has caught an exception: {$e->getMessage()}"; } 为什么{$e->getMessage()}必须用括号括起来? 有没有关于这个PHP手册的任何链接的解释? 我

Hyphens in Keys of Object

I have an stdClass Object like this: stdClass Object ( [key-west] => 1 [disney-land] => 1 ) I am trying to retrieve the value like this: $objectName->key-west but the value returned is 0. Why? and How can I retrieve it as 1? Thanks echo $objectName->{'key-west'};

对象的关键字中的连字符

我有这样一个stdClass对象: stdClass Object ( [key-west] => 1 [disney-land] => 1 ) 我试图检索像这样的值: $objectName->key-west 但返回的值是0.为什么? 和我如何检索它为1? 谢谢 echo $objectName->{'key-west'};

Why is ${0x0} correct?

The following code is working perfectly: ${0x0} = 'test'; echo ${0x0}; // prints "test" But I can't figure out why. 0x0 (or 0 , as non-hex people call it) is a random container, it could have been any number, but php variables can't start with a number. What's so special about the { } used here, and what are their limitations ? First of all, 0x0 is just a regular 0 in hexadecima

为什么$ {0x0}是正确的?

以下代码完美运行: ${0x0} = 'test'; echo ${0x0}; // prints "test" 但我不明白为什么。 0x0 (或0 ,因为非十六进制人称它为)是一个随机容器,它可以是任何数字,但php变量不能以数字开头。 这里使用的{ }什么特别之处,它们的局限性是什么? 首先, 0x0在十六进制表示中只是一个常量0 ,当与变量变量语法一起使用时,它将转换为字符串'0 ': var_dump(0x0===0); // prints "bool(true)" ${0x0} = 'test'; ec

Use of Brackets

This question already has an answer here: Curly braces in string in PHP 5 answers This is pretty simple actually. Inside a string context, like when wrapped in quotes, when you need to parse an object attribute like a method or property you wrap it inside curly braces. So this can help explain the statement: print "Author: {$product->getProduct()}; Now second example is just an e

使用括号

这个问题在这里已经有了答案: 在PHP 5中的字符串大括号的答案 实际上这很简单。 在字符串上下文中,比如当用引号括起来的时候,当你需要解析一个对象属性,比如方法或属性时,它将它包裹在大括号内。 因此,这可以帮助解释说明: print "Author: {$product->getProduct()}; 现在第二个例子只是第一个例子的扩展,作者使用多行和圆括号来提高可读性。 它也可以写成: $b = "{$this->title}"; $b .= "({$t

PHP Syntax ${"field"}

This question already has an answer here: Curly braces in string in PHP 5 answers It's called Complex (curly) syntax This isn't called complex because the syntax is complex, but because it allows for the use of complex expressions. Any scalar variable, array element or object property with a string representation can be included via this syntax. Simply write the expression the sa

PHP语法$ {“field”}

这个问题在这里已经有了答案: 在PHP 5中的字符串大括号的答案 它被称为Complex (curly) syntax 这不称为复杂的,因为它的语法很复杂,但是因为它允许使用复杂的表达式。 任何具有字符串表示的标量变量,数组元素或对象属性均可通过此语法包含在内。 简单地写出表达式的方式与字符串外部的方式相同,然后将其包装在{和}中。 由于{不能被转义,这个语法只有在$紧跟在{之后才能被识别。 使用{ $获取文字{$。 一些例子

What '{$x}' stands for?

This question already has an answer here: Curly braces in string in PHP 5 answers It seems like it was a trick question, first to see if you know what curly braces are used for in a PHP string, but also to to see if you know what the difference between double and single quotes in PHP strings, where single quotes are not evaluated and double quotes are, eg: $name = "bob"; echo "hello $name";

什么'{$ x}'代表?

这个问题在这里已经有了答案: 在PHP 5中的字符串大括号的答案 看起来这是一个技巧性的问题,首先要看看你是否知道在PHP字符串中使用了大括号, 还要了解是否知道PHP字符串中的双引号和单引号之间的区别,其中单引号是没有评估和双引号,例如: $name = "bob"; echo "hello $name"; // hello bob echo 'hello $name'; // hello $name 我猜他们假设你会看到花括号,它用来隔离字符串中的变量,并且在不查看引号的情况下给出

PHP is Syntax wired behavior

This question already has an answer here: Curly braces in string in PHP 5 answers It's not weird. It's how that's intended to be. phpinfo() will output data in any case. If you want to capture it's output, then use ob_ (output buffering) functions: ob_start(); phpinfo(); $data = ob_get_contents(); ob_end_clean(); //var_dump($data); Your problem isn't related to syntax

PHP是Syntax wired行为

这个问题在这里已经有了答案: 在PHP 5中的字符串大括号的答案 这并不奇怪。 这就是它的目的。 phpinfo()将在任何情况下输出数据。 如果你想捕获它的输出,那么使用ob_ (输出缓冲)函数: ob_start(); phpinfo(); $data = ob_get_contents(); ob_end_clean(); //var_dump($data); 你的问题与语法无关。 PHPinfo是一种以HTML格式返回有关服务器上PHP环境的信息的函数(有关更多信息,请参阅http://us2.php.net/phpinf