I have an Associative Array that works perfectly. The issue I'm having comes after that.
After the array flip, $combo looks like:
$combo = array(0 => '2,4', 1 => '4,15', 2 => '2,15');
I'm looking for is for each time to be given to each combo above: 2,4 would have a time of 1.8, 4,15 would have a time of 1.1 and so on...
What I'm getting is the time repeated exactly the same in every loop, and I'm also getting the first place winner repeated every time, even if it's not included in the combo.
$position = array('1', '2', '3', '4');
$jersey = array('2', '4', '15', '20');
$AssocArr = array_combine($position, $jersey);
$combo = array('1,2', '2,3', '1,3');
$time = array('1.8', '1.1', '1.8');
foreach ($headers as $header) {
foreach ($time as $idx=>$ttext) {
if($header[1] === 'Multiples') {
foreach ($combo as &$value) {
$values = explode(',', $value, 2);
$comboGroups = array_intersect_key($AssocArr, array_flip($values));
$value = join(',', $comboGroups);
}
Code half fails from here:
$TimeEntities = false;
foreach ($combo as $selGrp) {
$xid = $selGrp;
$sel = explode(',', $selGrp);
foreach ($sel as $set=>$sel) {
$set = 1;
$sel = trim($sel);
if (!empty($sel)){
if (is_numeric($sel))
$TimeEntities[$sel][$sel.';'.$set] = array('number' => $sel, 'order'=>$set);
else
$TimeEntities[$sel][$sel.';'.$set] = array('name' => $sel, 'order'=>$set);
$set++;
}
}
$race['tracks'][$trackxid]['times']['final;' .$xid] = array('type'=>'final', $time'=>$ttext, 'combinations'=>$TimeEntities);
}
}
}
}
The outcome I would like should look like:
-<time xid="Multiples|final;2,4" type="final" time="1.8">
-<combination xid="Multiples|final;2,4|2">
<comboParticipant xid="Multiples|final;2,4|2|2;1" order="1" number="2"/>
</combination>
-<combination xid="Multiples|final;2,4|4">
<comboParticipant xid="Multiples|final;2,4|4|4;1" order="1" number="4"/>
</combination>
</time>
-<time xid="Multiples|final;1,15" type="final" time="1.1">
-<combination xid="Multiples|final;1,15|1">
<comboParticipant xid="Multiples|final;1,15|1|1;1" order="1" number="1"/>
</combination>
-<combination xid="Multiples|final;1,15|15">
<comboParticipant xid="Multiples|final;1,15|15|15;1" order="1" number="15"/>
</combination>
</time>
-<time xid="Multiples|final;2,15" type="final" time="1.8">
-<combination xid="Multiples|final;2,15|2">
<comboParticipant xid="Multiples|final;2,15|2|2;1" order="1" number="2"/>
</combination>
-<combination xid="Multiples|final;2,4|4">
<comboParticipant xid="Multiples|final;2,15|15|15;1" order="1" number="15"/>
</combination>
</time>
I know this is a lot of code to figure out. I do hope someone can help. I appreciate it immensely. Thanks! :)