PHP 关联数组,多维.我如何访问它们? [英] PHP associate arrays, multidimension. How do I access them?

查看:36
本文介绍了PHP 关联数组,多维.我如何访问它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解这个问题.我有一个名为 $a 的数组,这是 print_r 显示的内容:

I'm having hard time wrapping my head around this. I have an array called $a and here's what print_r shows:

Array
(
    [Rows] => Array
        (
            [Row] => Array
                (
                    [0] => Array
                        (
                            [ContactId] => 26525fea-20c5-43e5-afd2-0001
                        )

                    [1] => Array
                        (
                            [ContactId] => 73b402e6-f7b9-45da-89f4-0002
                        )

                    [2] => Array
                        (
                            [ContactId] => e6a1f356-7838-494b-8e1e-000
                        )

我如何只对数字 2 中的数据进行回显?我只想输出e6a1f356-7838-494b-8e1e-000".谢谢.

How do I do an echo of just the data in number 2? I just want to output "e6a1f356-7838-494b-8e1e-000". Thanks.

感谢您的出色回复.另外,我不知道如何做这个数组的 sizeof ?我是否需要编写一个 for 循环来遍历每个直到它为空,或者 sizeof 是否以某种方式与此一起工作?

edit: Thanks for the excellent replies. Also, I cant figure out how to do a sizeof of this array? Will I need to write a for loop to go through each until its empty or does sizeof somehow work with this?

推荐答案

任何数组变量名后都可以有['key'][N] 来访问数组中的一个值.如果那个值也是一个数组,你可以放另一组 [] 来访问该数组中的值,这是下一层:

Any array variable name can have ['key'] or [N] after it to access a value in the array. If that value is also an array, you can put another set of [] to access values in that array, which is the next level:

echo $a['Rows']['Row'][2]['ContactId'];

这篇关于PHP 关联数组,多维.我如何访问它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆