1

I am reading from the excel file two columns. One contains old ids and the other one returns new ids. So I am having two arrays:

$newAttributeIDs and $oldAttributeIDs

If I do count of each array separatly, I will get this result:

var_dump(count($newAttributeIDs)); // result is 3440
var_dump(count($oldAttributeIDs)); // result is 3440

And I would like to have key value pair of this values, but when I do:

$keyValueNewOldAttributeIDs = array_combine($oldAttributeIDs, $newAttributeIDs);

And then:

var_dump(count($keyValueNewOldAttributeIDs)); // result is 1990

I am getting wrong result, and some ids are now missing in the $keyValueNewOldAttributeIDs array. Does anyone knows what is causing this? Thanks!

5
  • 2
    Are all the values in $oldAttributeIDs unique? Commented Jun 24, 2019 at 12:32
  • No, I just checked, I did var_dump(count(array_unique($oldAttributeIDs))); and it returned 1990. Commented Jun 24, 2019 at 12:34
  • 5
    There you go then. You can't have an array with duplicate keys. Commented Jun 24, 2019 at 12:34
  • array_merge will not return key, value pair of the two arrays. Commented Jun 24, 2019 at 12:35
  • @user2450639 Show the arrays you have(just a sample) and your expected output. Then we can tell you what went wrong. Commented Jun 24, 2019 at 12:49

1 Answer 1

1

I solve this flipping the values. Since I had some of the same values in the $oldAttributeIDs, result was unexpected. First value should have all unique values in the array. I missed that fact.

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

Comments

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.