如何访问多维数组中的数组元素?
这是我的数组的表示:
$arr
[0]
[code]='a code'
[number]='a number'
[1]
[code]='a code'
[number]='a number'
[2]
[code]='a code'
[number]='a number'
[3]
.
.
我正在执行一个 foreach 循环来获取所有被卡住的 [code] 值:我忘记了如何做到这一点。有人可以帮我吗?
Here's a representation of my array:
$arr
[0]
[code]='a code'
[number]='a number'
[1]
[code]='a code'
[number]='a number'
[2]
[code]='a code'
[number]='a number'
[3]
.
.
I'm doing a foreach loop to get all the [code] values am stuck: I forgot how to do it. Can anyone please help me with it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将数组转换为 stdClass 类型的对象
,但是,您的帖子标题似乎暗示您想要一个对象,但帖子正文似乎您只想访问数组键。
在这种情况下,您可以只使用以下内容。但这取决于“获取所有[代码]值”到底是什么意思。
You can just cast the array as an object of type stdClass
That said however, your post title seems to imply you want an object, but the post body seems like you just want to access an array key.
In which case you can just use the following. But it depends what exactly you mean by 'get all of the [code] values.'
也许是这样的:
我希望它会有所帮助!
Maybe something like :
I hope it will help !
我希望这有帮助。
I hope this helps.