user2450639
user2450639

Reputation: 306

PHP array_combine is not returning all the values

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!

Upvotes: 1

Views: 115

Answers (1)

user2450639
user2450639

Reputation: 306

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.

Upvotes: 1

Related Questions