3 回答
TA贡献1827条经验 获得超8个赞
建立新的数组数据并将其添加到最后而不是每个阶段的主数组中会更容易......
$MyObject = [];
foreach($Xml->Sequences->Sequence as $var=>$value) {
$newObject =array(
"title" => $value->SequenceName->__toString(),
"folder" => true,
);
foreach ($value->SequencePackages->Package as $a=>$b){
$newObject["children"][] = ["title" => $b->PackageFolder->__toString()];
}
$MyObject[] = $newObject;
}
TA贡献1757条经验 获得超7个赞
用于创建数组的父循环的用户索引。
$MyObject[$var] = array(
"title" => $value->SequenceName->__toString(),
"folder" => true
);
$MyObject[$var]['children'][] = array(array(
"title" => $b->PackageFolder->__toString(),
));
TA贡献1848条经验 获得超10个赞
你需要做一些这样的事情。您需要使用父数组中的键并插入新值子 foreach($Xml->Sequences->Sequence as $var=>$value) {
$MyObject[] = array(
"title" => $value->SequenceName->__toString(),
"folder" => true,
);
foreach ($value->SequencePackages->Package as $a=>$b){
$MyObject[‘children’] = array(
"title" => $b->PackageFolder->__toString(),
);
}
}
- 3 回答
- 0 关注
- 95 浏览
添加回答
举报