开发者

PHP associate arrays, multidimension. How do I access them?

开发者 https://www.devze.com 2023-03-19 23:59 出处:网络
I\'m having hard time wrapping my head around this. I have an array called $a and here\'s what print_r shows:

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
                        )

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

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?


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'];


I believe it'd be:

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


You can traverse/access an array by its keys as shown by the print_r() output.

For example:

echo $a['Rows']['Row'][2]['ConactId'];
0

精彩评论

暂无评论...
验证码 换一张
取 消