Okay So heres the issue, using an api (lyris hq) i am being returned this xml dataset
<DATASET>
<TYPE>success</TYPE>
<RECORD>
<DATA type="name" id="205199">Dev1</DATA>
<DATA type="messages">4</DATA>
<DATA type="last-sent">Jun. 26, 2012</DATA>
<DATA type="members">1</DATA>
<DATA type="status">active</DATA>
<DATA type="cache-time">2012-06-26T18:21:18+00:00</DATA>
</RECORD>
<RECORD>
<DATA type="name" id="206378">Dev2</DATA>
<DATA type="messages">1</DATA>
<DATA type="last-sent"></DATA>
<DATA type="members">2</DATA>
<DATA type="status">active</DATA>
<DATA type="cache-time">2012-05-31T14:47:12+00:00</DATA>
</RECORD>
<RECORD>
<DATA type="name" id="206379">Dev3</DATA>
<DATA type="messages">1</DATA>
<DATA type="last-sent"></DATA>
<DATA type="members">1</DATA>
<DATA type="status">active</DATA>
<DATA type="cache-time">2012-05-31T14:47:12+00:00</DATA>
</RECORD>
<RECORD>
<DATA type="name" id="206380">Dev4</DATA>
<DATA type="messages">1</DATA>
<DATA type="last-sent"></DATA>
<DATA type="members">1</DATA>
<DATA type="status">active</DATA>
<DATA type="cache-time">2012-05-31T14:47:12+00:00</DATA>
</RECORD>
</DATASET>
What I’m attempting to do is create an array using SimpleXMLElement using it in this format recursively
$response = array(
'{listid (id attribute from name element)}' => array(
'{other attribute type}' => '{value}'
),
);
example of this using the dev1 (first record)
$response = array(
'205199' => array(
'name' => 'Dev1',
'messages' => '4',
'last-sent' => 'Jun. 26, 2012',
'members' => '1',
'status' => 'active',
'cache-time' => '2012-06-26T18:21:18+00:00'
),
);
me and several members of the web team here have bashed our heads on this for a while and are getting no where so I’m hoping i can get some assistance from the hives mind so to speak lol
heres a pitiful example of what i was last attempting to use to get my result which failed obviously
foreach ($responseobj->RECORD as $value) {
$returnarray[(string)$value->DATA['id']] = array();
foreach ($value->DATA as $k => $v) {
echo '<pre>';
print_r($v);
echo '</pre>';
$returnarray[(string)$v['id']] = array((string)$v['type'] => (string)$v,);
}
}
1 Answer