开发者

How can i get the values from this array?

In $attval when use foreach loop to print out the elements I get this output:

Array( 
      [0]
         (
          [id]=>1,
          [name]=>xxx
         )
      [0]
         (
          [id]=>2,
          [name]=>abc
         )
)

For some reason both indices are t开发者_如何学编程he same. I think I can still get the values using the multidimensional array, but i am confused as to how I can?


Assuming your code is something like this:

$attval = array();
$attval[0] = array("id"=>1,"name"=>"xxx");
$attval[1] = array("id"=>2,"name"=>"abc");

You can access individual properties like this:

$attval[0]['id']; // 1
$attval[1]['name']; // abc

You are showing a print_r of each sub-array, therefore your output should be:

Array
(
    [id] => 1
    [name] => xxx
)
Array
(
    [id] => 2
    [name] => abc
)

If you want a full view of the array you could just do:

print_r($attval);

Then you get:

Array
(
    [0] => Array
        (
            [id] => 1
            [name] => xxx
        )

    [1] => Array
        (
            [id] => 2
            [name] => abc
        )

)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜