我有以下xml:
<result>
<rowset name="jumpClones" key="jumpCloneID" columns="jumpCloneID,typeID,locationID,cloneName"/>
<rowset name="jumpCloneImplants" key="jumpCloneID" columns="jumpCloneID,typeID,typeName"/>
<rowset name="implants" key="typeID" columns="typeID,typeName">
<row typeID="9899" typeName="Ocular Filter - Basic"/>
<row typeID="9941" typeName="Memory Augmentation - Basic"/>
<row typeID="9942" typeName="Neural Boost - Basic"/>
<row typeID="9943" typeName="Cybernetic Subprocessor - Basic"/>
<row typeID="9956" typeName="Social Adaptation Chip - Basic"/>
</rowset>
</result>为了获得Ocular Basic的值,我使用/通过rowset的索引:
$array->result->rowset[2]->row[0]["typeName"];
// ^现在,rowset2有:name=“植入物”
因此,如何使用数组索引属性名称(implants)来获取值,而不是指向索引2
我试过:
$array->result->rowset["implants"]->row[0]["typeName"];但没起作用。正确的解决办法是什么?
发布于 2015-02-26 00:35:31
如果您希望使用implants作为获取该节点的基础,而不是选择索引(因为这可能会有所不同),则可以使用xpath,如果找到指向它,则访问它的子查询。示例:
$implants = $array->xpath('//rowset[@name="implants"]');
if(!empty($implants)) {
echo $implants[0]->row[0]->attributes()->typeName;
}https://stackoverflow.com/questions/28732296
复制相似问题