Array keys and case sensitivity

March 29th, 2005. Tagged: PHP certification

Yep, array keys are case sensitive.
So you can do:
< ?php
$a = array('key'=> 1, 'Key' => 2);
?>and it will print

Array ( [key] => 1 [Key] => 2 )

Similarly if you call array_keys() on $a, like:
< ?php
$a = array('key'=> 1, 'Key' => 2);
?>'ll get:

Array ( [0] => key [1] => Key )

Defining the same key in an array (even in the same array declaration) won't cause an error, but will result in the latest value taking precedence. Like:
< ?php
$a = array('key'=> 1, 'key' => 2);
?>will output:

Array ( [key] => 2 )

Tell your friends about this post: Facebook, Twitter, Google+

One Response

  1. I was recommended this blog by means of my cousin. I’m no longer certain whether or not this publish is written by means of him as no one else realize such distinct about my problem. You are amazing! Thanks!

Leave a Reply