Jump to content

Trying to group an xml array by attribute and pir


nade93

Recommended Posts

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

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):



$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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.