PHP:变量(数组)是函数吗?

发布于 2024-09-29 18:01:47 字数 466 浏览 8 评论 0原文

我不明白这段代码中这些字符 -> 的功能:

$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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

昔梦 2024-10-06 18:01:47

$var 是一个对象。

getImageInfo() 是该对象的一种方法 - 该方法返回一个数组。

如果您想获取特定信息:

$info = $var->getImageInfo();
$fileName = $info['fileName'];

$var is an object.

getImageInfo() is one method of this object - this method returns an array.

if you want to get a specific info:

$info = $var->getImageInfo();
$fileName = $info['fileName'];
注定孤独终老 2024-10-06 18:01:47

在您的示例中,$var->getImageInfo(), 变量$var 是类的实例(也称为对象)。函数getImageInfo() 被称为类方法。这是面向对象编程的一部分,也称为 OOP。您可以在这里了解更多信息 - http://php.net/manual/en/language .oop5.php

如果您想获取列出的数组的特定成员,您可以简单地执行以下操作:

$image_info = $var->getImageInfo();
echo $image_info['fileSize'];

In your example, $var->getImageInfo(), the variable $var is an instance (also called an object) of a class. The function getImageInfo() 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.php

If you want to get a particular member of the array that you listed, you can simply do:

$image_info = $var->getImageInfo();
echo $image_info['fileSize'];
可是我不能没有你 2024-10-06 18:01:47

函数“getImageInfo()”填充变量“$var”。

不,实际上它调用了对象 $var 上的方法 getImageInfo()

为了使用返回的数组,请执行以下操作:

$res = $var->getImageInfo();
print $res['fileName'];

文档

the function "getImageInfo()" populates the variable "$var".

No, actually it calls the method getImageInfo() on the object $var.

In order to use the returned array, do this:

$res = $var->getImageInfo();
print $res['fileName'];

Read more about working with objects in PHP in the documentation.

万劫不复 2024-10-06 18:01:47

$var 是一个对象(类),getImageInfo 是该类中返回数组的函数。将结果数组保存到另一个变量中以读取其内容。

$array = $var->getImageInfo();
echo $array['fileSize'];

$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.

$array = $var->getImageInfo();
echo $array['fileSize'];
木有鱼丸 2024-10-06 18:01:47

您正在使用以下命令调用类内的函数:

$var->getImageInfo()

要将其放入常规变量中以访问特定键,您只需将其分配给普通变量即可:

$this = $var->getImageInfo();
echo $this['FileSize'];

You are making a call to a function inside a class with this:

$var->getImageInfo()

To get it into a regular variable to access specific keys, you just need to assign it to a normal variable a la:

$this = $var->getImageInfo();
echo $this['FileSize'];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文