【发布时间】:2019-08-11 18:20:09
【问题描述】:
我有这个数组 ($item):
Array
(
[categoria] => Array
(
[0] => Array
(
[tid] => 6737
[name] => Sala VIP
[endereco] =>
[logo] =>
[image] =>
[link] => /taxonomy/term/6737
[site] =>
[color] =>
[peso] => 0
[icone] => 1
[url_emissores] =>
)
)
[destaque] => 1
)
我想比较$something 是否等于[name] => Sala VIP。我怎样才能做到这一点?我正在尝试:
if($something == $item[categoria][0].name) {
#code
}
【问题讨论】:
-
$item['categoria'][0]['name'] -
@Jonnix 谢谢人
-
@Jonnix 真的有必要在单词之间使用''吗?不能只是 $item[categoria][0][name] 吗?
-
@VitorMascia 它可以工作,但我不推荐它。如果没有引号,它将首先尝试使用带有这些名称的常量,而不是将它们视为字符串。为了 2
',只需要使用显式字符串即可。 -
@VitorMascia - 你可以使用它,但你会收到警告。
Use of undefined constant foo assuming 'foo'或类似的东西。