这在 PHP 中是什么意思 ->或 => [英] What Does This Mean in PHP -> or =>

查看:21
本文介绍了这在 PHP 中是什么意思 ->或 =>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
我们使用对象运算符->"的地方在 php 中
参考 - 这个符号在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆