nade93 Posted March 27, 2014 Share Posted March 27, 2014 hi all I am trying to get one printed result from an attribute that is pulling from a nested array I am pulling a top layer for the header then placing the items under the header foreach ($x as $p=>$t): // get the type for drill down to market ?> <div id='feedhead'><? echo $t['name']; ?></div> <? foreach ($t as $m): so the $m['url'] is the thing i am wanting to group by as is it pulling things that are duplicating. so if did below for example echo $m['url'].'<br>'; would output as http://google.com http://google.com http://google.com http://google.com however would want just the single output from the loop http://google.com how do i go about this? thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/287345-trying-to-group-an-xml-array-by-attribute-and-pir/ Share on other sites More sharing options...
requinix Posted March 27, 2014 Share Posted March 27, 2014 (edited) Shouldn't you fix the data so it's not duplicated? If you had PHP 5.5 you could use array_column. Otherwise manually build up a new array of only the unique values and loop over that one instead. $munique = array(); foreach ($t as $m) { $munique[$m['url']] = $m; } foreach ($munique as $m): Edited March 27, 2014 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/287345-trying-to-group-an-xml-array-by-attribute-and-pir/#findComment-1474203 Share on other sites More sharing options...
nade93 Posted March 27, 2014 Author Share Posted March 27, 2014 thanks for the replay however When I implement that no results (inluding the header) pull at all Quote Link to comment https://forums.phpfreaks.com/topic/287345-trying-to-group-an-xml-array-by-attribute-and-pir/#findComment-1474210 Share on other sites More sharing options...
requinix Posted March 28, 2014 Share Posted March 28, 2014 Then it might have something to do with the lots of code you didn't post. So. How about posting everything you have in that file? Quote Link to comment https://forums.phpfreaks.com/topic/287345-trying-to-group-an-xml-array-by-attribute-and-pir/#findComment-1474239 Share on other sites More sharing options...
nade93 Posted March 28, 2014 Author Share Posted March 28, 2014 $xml = simplexml_load_file('http://cachepricefeeds.williamhill.com/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=1&marketSort=--&filterBIR=Y'); $x = $xml->response->williamhill->class->type; foreach ($x as $p=>$t): // get the type for drill down to market ?> <div id='feedhead'><? echo $t['name']; ?></div> <? foreach ($t as $m): // get the attributes for the market //-------- GET THE DATES IN ORDER $d = explode('-', $m['date']); $date = $d[2].'/'.$d[1].'/'.$d[0]; echo $m['url']; endforeach; endforeach; Quote Link to comment https://forums.phpfreaks.com/topic/287345-trying-to-group-an-xml-array-by-attribute-and-pir/#findComment-1474264 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.