-7

I have an array which is getting from user formatted json, like this

'UA27' => [
    'PRODUCT' => 'S',
    'CANBECONSUMED' => true
],
'UA28' => [
    'PRODUCT' => 'R',
    ]
],
'UA29' => [
    'PRODUCT' => 'O',
    'CANBECONSUMED' => true
],
'UA29' => [
    'PRODUCT' => 'O',
    'CANBECONSUMED' => false
],
'UA31' => [
    'PRODUCT' => 'P',
    'CANBECONSUMED' => true
]

But I have to figure out if there is more than one array with the same key to show that user has error with json.

Thank you.

User
  • 1
  • 2
  • [Array can't have same key twice.Two identical index are defined, the last overwrite the first.](http://stackoverflow.com/questions/30636179/how-does-php-index-associative-arrays/30636430#30636430) – Narendrasingh Sisodia Aug 31 '15 at 11:32

1 Answers1

1

Arrays can't have the same key twice. First one will be smashed and replaced by the second one.

Ignacio Ruiz
  • 611
  • 10
  • 21
  • Thank you. I know that but I need to determine if there is same key in this array. It is obviously we can see that but I need to determine this on server-side. Because I get this array from user – User Aug 31 '15 at 11:36
  • @User take a look at `array_key_exists()`. – Sougata Bose Aug 31 '15 at 11:38
  • @User You can't. There **can't** be 2 identical keys in one array, it's impossible – Rizier123 Aug 31 '15 at 11:38
  • @b0s3 `array_key_exists()` is useless and misleading, since there simply can't be an array with duplicate keys. – Rizier123 Aug 31 '15 at 11:38
  • 1
    @Rizier123 My bad. I just considered *I need to determine if there is same key in this array* on the comment. :) – Sougata Bose Aug 31 '15 at 11:41