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

Link to comment
Share on other sites

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 by requinix
Link to comment
Share on other sites




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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.