Skip to content
Advertisement

Why can’t I add a key and value when PHP array_key_exists is FALSE?

I am simply trying to add a set of keys and values to an array if and only if they are not already in the array. I need to add d1 thru d20 when they are not already in the array,

Here is my code.

print_r($demos_keys)

JavaScript
JavaScript

print_r($rowdata);

JavaScript

I CAN add d04 by inserting $rowdata_tmp[‘d04’] = ”; before the array_combine statement, but the problem is that d04 will sometimes already be present in demos_keys.

Can someone help? I’m dying here.

Advertisement

Answer

You’re checking for the key in the top-level $rowdata array, not the new row that you’re adding to the array.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement