在PHP中,带有两个这样的括号的(数组)是什么意思? [英] What does (array) with two parentheses like this mean in PHP?
本文介绍了在PHP中,带有两个这样的括号的(数组)是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最近我一直在阅读一些代码,并且遇到了一些实例,在这些实例中,开发人员会将括号括起来,如下例所示.
I've been reading some code recently and I've come across a few instances where the developer would wrap parentheses around like following example.
有此功能:
foreach ((array) $middleware as $m) {
$this->middleware[] = [
'middleware' => $m,
'options' => &$options,
];
}
在每次检查中,都有一个带有括号的数组(array)
,这是什么意思.
In the for each check there's array (array)
with parentheses around, what do these mean.
或者有人可以指导我阅读文档,以便我阅读此问题. 预先感谢.
Or can someone guide me to a doc where I can read up on this matter. Thanks in advance.
推荐答案
这称为它强制$ middleware为数组数据类型.一些例子:
It forces $middleware to an array data type. Some examples:
(array) [1,2] // [1,2]
(array) 1 // [1]
(array) stdClass{hello: world} // [hello => world] (object to array pseudocode)
这篇关于在PHP中,带有两个这样的括号的(数组)是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文