I have a code that gives me exactly the right output, but I keep getting errors during the process, and I'm not allowed to use @ to stop the errors. :(
$som = '';
foreach ($prizeStr as $som=>$ptext) {
$Cloth = $AssocArr[$som+1];
//doing something else here etc...
}
I have an array of prize money ($prizeStr), it's unknown how many amounts of money there will be. I need each place getter to have a prize amount until there's none left. I realise that $ptext is each prize amount, and $som is the key, then I've converted the key into the associative array, and found the Number of the runner. I can't figure out a way to get rid of that error message that gives me "undefined offset" errors.
I've tried
$AssocArr[$som]++;
and that doesn't work, I've tried isset, but that gives me the same issue. I've also tried to put it as:
$AssocArr[$som];
$som++;
But nothing is working... Any ideas you guys have would be great. Let me know if you need more info... and Thanks in advance!
EDIT: I have (for example) I pregmatched something to create my associative array ended up with:
$position = 1;
$AssocArr[$position] = $cloth;
$position++;
essentially giving me:
$AssocArr = array(1=>2,2=>4,3=>15,4=>20,5=>17,6=>1,7=>6,8=>12);
I pregmatched again to get the prize string of:
$prizeStr = array('11.40', '5.00', '2.90', '1.80', '3.50');
Then I get to the error part. Thing is, the above prize string could have 5 values or 10 values or whatever. What I need to do is have 1 prize amount per winner, which the code does, it just gives me an illegal offset, which I'm trying to get rid of. That's what I'm trying to do.
foreach($prizeStr as $som=>$ptext) {
$Cloth = $AssocArr[$som+1];
// this finds the position keys and increases it by 1.
end result should be winner: 2 = 11.40, then places: 2 = 5.00, 4 = 2.90, 15 = 1.80 etc... Does that make more sense? I hope that helps more. Thanks!
EDIT: In doing more testing, I realise that I need to build the array before the code can continue. I'm getting the offset error because my array isn't complete before my code tries to call the key it needs. Can anyone help me build it before I do the rest?