是不是可以用foreach这样做?

时间:2017-01-11 16:11:12

标签: php arrays foreach


我有这个代码,我不确定它是否正确 我收到错误:

Warning: Invalid argument supplied for foreach()

我从我的mysql数据库xmldata创建这个数组

$array_xml = array();
$array_xml = xml2array($row['xmlData']);

$moneyDetails = array();
$moneyDetails = $array_xml['some1']['some2']['some3']['some4']['some5']['some6']['some7']['some8']['some9'];


foreach($moneyDetails->ContributionData AS $ContributionData){
    $ContributorCode = $ContributionData->ContributorCode;

    echo $ContributorCode;

}

1 个答案:

答案 0 :(得分:2)

如果$ moneyDetails是一个数组,那么试试

### Create the Vertex Animal
cluster_id = client.command("create class Animal extends V")
print(cluster_id)
### Insert a new value
client.command("insert into Animal set name = 'rat', specie = 'rodent'")

你正在解决它就像它是一个对象