在PHP中这是什么意思->或=> [英] What Does This Mean in PHP -> or =>
问题描述
可能重复:
使用对象运算符->"的地方在php中
参考-此符号在PHP中是什么意思? >
Possible Duplicate:
where we use object operator "->" in php
Reference - What does this symbol mean in PHP?
我一直在PHP中看到这些内容,但是我对它们的实际含义一无所知. ->
的作用和=>
的作用.我不是在谈论运营商.他们是别的东西,但似乎没人知道...
I see these in PHP all the time but I don't have a clue as to what they actually mean. What does ->
do and what does =>
do. And I'm not talking about the operators. They're something else, but nobody seems to know...
推荐答案
双箭头运算符,=>
,用作数组的访问机制.这意味着在数组上下文中,左侧的内容将具有与右侧相应的值.这可用于将任何可接受类型的值设置为数组的相应索引.索引可以是关联的(基于字符串)或数字.
The double arrow operator, =>
, is used as an access mechanism for arrays. This means that what is on the left side of it will have a corresponding value of what is on the right side of it in array context. This can be used to set values of any acceptable type into a corresponding index of an array. The index can be associative (string based) or numeric.
$myArray = array(
0 => 'Big',
1 => 'Small',
2 => 'Up',
3 => 'Down'
);
对象运算符,->
,在对象范围内用于访问对象的方法和属性.意思是说,运算符右侧是实例化到运算符左侧变量中的对象的成员.实例化是此处的关键术语.
The object operator, ->
, is used in object scope to access methods and properties of an object. It’s meaning is to say that what is on the right of the operator is a member of the object instantiated into the variable on the left side of the operator. Instantiated is the key term here.
// Create a new instance of MyObject into $obj
$obj = new MyObject();
// Set a property in the $obj object called thisProperty
$obj->thisProperty = 'Fred';
// Call a method of the $obj object named getProperty
$obj->getProperty();
这篇关于在PHP中这是什么意思->或=>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!