smilesmita Posted August 6, 2007 Share Posted August 6, 2007 hi there, this is a kind of array i get after i have parsed my xml. now i wanted to extract data from this array: name and cdata elements needs to be extracted.any ideas? [2] => Array ( [name] => DELIVERY [attrs] => Array ( ) [children] => Array ( [0] => Array ( [name] => PACKAGEREFERENCENUMBER [attrs] => Array ( ) [children] => Array ( [0] => Array ( [name] => CODE [attrs] => Array ( ) [cdata] => IK ) [1] => Array ( [name] => VALUE [attrs] => Array ( ) [cdata] => 66759 ) ) ) Link to comment https://forums.phpfreaks.com/topic/63604-solved-extracting-array-elements/ Share on other sites More sharing options...
Barand Posted August 6, 2007 Share Posted August 6, 2007 <?php $data = array ( '2' => Array ( 'name' => 'DELIVERY', 'attrs' => Array ( ), 'children' => Array ( '0' => Array ( 'name' => 'PACKAGEREFERENCENUMBER', 'attrs' => Array ( ), 'children' => Array ( '0' => Array ( 'name' => 'CODE', 'attrs' => Array ( ), 'cdata' => IK ), '1' => Array ( 'name' => 'VALUE', 'attrs' => Array ( ), 'cdata' => 66759 ) ) ) ) ) ); foreach ($data[2]['children'][0]['children'] as $childArray) { echo 'Name : ', $childArray['name'], '<br>'; echo 'CData : ', $childArray['cdata'], '<br><br>'; } ?> Link to comment https://forums.phpfreaks.com/topic/63604-solved-extracting-array-elements/#findComment-316966 Share on other sites More sharing options...
smilesmita Posted August 6, 2007 Author Share Posted August 6, 2007 hi thanks for he solution.i have one question on that though... how do i convert my array to the modifications you have done to my array. like u added "data= and 'children','0'..? that is the array when i convert xml into array? any idea abt how i can get this array matched with the array you have shown in your solution?> Thanks again ! Link to comment https://forums.phpfreaks.com/topic/63604-solved-extracting-array-elements/#findComment-316972 Share on other sites More sharing options...
Barand Posted August 6, 2007 Share Posted August 6, 2007 I added $data because I had to call it something. I have no way of knowing what you called it, and as it was an extract, starting at element 2, I have no way of knowing the full structure of your array. The "children" and "0" etc are the keys in your array, not added by me. Link to comment https://forums.phpfreaks.com/topic/63604-solved-extracting-array-elements/#findComment-317007 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.