1
foreach( $notZeroValue as $cardSetPosition => $timesChosen){
    echo $groupValue;
    $notZeroValue[$cardSetPosition + ($groupValue*100)] = $notZeroValue[$cardSetPosition];
    unset ($notZeroValue[$cardSetPosition]);
}

Output is 0000 (correct because the $notZeroValue has four elements and for each one $groupValue = 0)

I know there must be a newbie error because changing *100 to +100 produces key values 101, 102, 103, 104.

print_r($notZeroValue); //output = array()
2
  • 2
    So what is the question or problem you're having? Commented Nov 22, 2011 at 13:40
  • I think you have to provide more information. Where is $groupValue defined? What does the array look like? What is the result you get and what is the result you expect? Commented Nov 22, 2011 at 13:41

1 Answer 1

3

With $groupValue equal to 0 you are getting correct results because

$notZeroValue[$cardSetPosition + ($groupValue*100)] = $notZeroValue[$cardSetPosition];

becomes

$notZeroValue[$cardSetPosition] = $notZeroValue[$cardSetPosition];

which is overwriting the array value with itself.

Next you delete the element from array.

So at the end the array will be empty.

But when you change * to + and $groupValue still at 0:

$notZeroValue[$cardSetPosition + ($groupValue+100)] = $notZeroValue[$cardSetPosition];

you'll not be overwriting the array values, instead you'll be creating new key/value pairs where keys are 100 more than old keys. Next you delete the old key/value from the array. So at the end you've 4 new key/value pairs.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah! I hadn't realised that! Ok I'll add an if for when $groupValue == 0 THANKS!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.