PHP:变量(数组)是函数吗?
我不明白这段代码中这些字符 ->
的功能:
$var->getImageInfo();
函数“getImageInfo()”填充变量“$var”。
我可以使用 print_r 函数显示所有值,但如何获取特定值
echo "<pre>";
print_r($var->getImageInfo());
echo "</pre>";
返回
Array
(
[resolutionUnit] => 0
[fileName] => 1.jpg
[fileSize] => 30368 bytes
...
)
例如如何获取“fileSize”?
I dont understand the function of these characters ->
in this code:
$var->getImageInfo();
the function "getImageInfo()" populates the variable "$var".
I can use the print_r function to display all values but how do I get a specific value
echo "<pre>";
print_r($var->getImageInfo());
echo "</pre>";
returns
Array
(
[resolutionUnit] => 0
[fileName] => 1.jpg
[fileSize] => 30368 bytes
...
)
how do I get "fileSize" for instance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
$var 是一个对象。
getImageInfo() 是该对象的一种方法 - 该方法返回一个数组。
如果您想获取特定信息:
$var is an object.
getImageInfo() is one method of this object - this method returns an array.
if you want to get a specific info:
在您的示例中,
$var->getImageInfo(),
变量$var
是类的实例(也称为对象)。函数getImageInfo()
被称为类方法。这是面向对象编程的一部分,也称为 OOP。您可以在这里了解更多信息 - http://php.net/manual/en/language .oop5.php如果您想获取列出的数组的特定成员,您可以简单地执行以下操作:
In your example,
$var->getImageInfo(),
the variable$var
is an instance (also called an object) of a class. The functiongetImageInfo()
is known as a class method. This is part of Object Oriented Programming, also called OOP. You can learn more about this here - http://php.net/manual/en/language.oop5.phpIf you want to get a particular member of the array that you listed, you can simply do:
不,实际上它调用了对象
$var
上的方法getImageInfo()
。为了使用返回的数组,请执行以下操作:
在 文档。
No, actually it calls the method
getImageInfo()
on the object$var
.In order to use the returned array, do this:
Read more about working with objects in PHP in the documentation.
$var 是一个对象(类),
getImageInfo
是该类中返回数组的函数。将结果数组保存到另一个变量中以读取其内容。$var is an object (class), and
getImageInfo
is a function in that class that returns an array. Save the resulting array into another variable to read its contents.您正在使用以下命令调用类内的函数:
要将其放入常规变量中以访问特定键,您只需将其分配给普通变量即可:
You are making a call to a function inside a class with this:
To get it into a regular variable to access specific keys, you just need to assign it to a normal variable a la: