0

这是一些复杂的多维数组的输出:

    Array ( 
           [0] => Array ( 
                       [@attributes] => Array ( [ID] => 114037469 [Name] => MJBDESIGN.ORG [Traffic] => 4 [BidCount] => 0 [Price] => $8 USD [ValuationPrice] => - [TimeLeft] => 3H 27M [RowID] => 1 ) 
           ) 
           [1] => Array ( 
                       [@attributes] => Array ( [ID] => 114136929 [Name] => TRAININGPROGRAMMEDESIGN.COM [Traffic] => 11 [BidCount] => 0 [Price] => $8 USD [ValuationPrice] => $3 USD [TimeLeft] => 3H 27M [RowID] => 2 ) 
           ) 
)

如何遍历每个项目并获取单个项目的“ID”、“名称”等?谢谢

4

5 回答 5

5

这个数组并没有那么复杂。

$simpleArray = __YOUR_COMPLEX_ARRAY__;
foreach ($simpleArray as $array) {
    $id = $array['@attributes']['ID'];
    $name = $array['@attributes']['Name'];
}
于 2013-08-30T12:50:11.427 回答
1
foreach ($array as $r) {
  $name = $r['@attributes']['Name'];
  $id = $r['@attributes']['ID'];
  # code ....
}
于 2013-08-30T12:50:25.480 回答
1

如果您想要每行的所有属性:

foreach ($array as $n=>$r){
    echo "Row {$n}\n";
    foreach ($r as $k=>$v){
        // Echo the data
        echo "{$k}=>${v}\n";
    }
}
于 2013-08-30T12:53:02.567 回答
1

简单的方法:

$array = // your long array;

foreach($array as $row)
{
    $id = $row['@attributes']['Id'];
    $name = $row['attributes']['Name'];
    // do something with these variables
}
于 2013-08-30T12:54:13.813 回答
0

试试看,

foreach ($yourarray as $val) {
    echo $id = $val['@attributes']['ID'];
    echo $name = $val['@attributes']['Name'];
}
于 2013-08-30T12:51:14.713 回答