Showing posts with label arrays. Show all posts
Showing posts with label arrays. Show all posts

Wednesday, July 13, 2016

PHP Array indexes are CaSe-SeNsiTIvE

Devs,

Quick note, PHP array indexes are CaSe-SeNsiTIvE.

I ran into an issue with sending a $_POST to the database to insert a record. I was validating the data in the post array and setting required values if a key was not set properly. However, this gave me a database insert error stating I'm using duplicate field (column) names.

Well, ain't that tricky!

Did a quick search to confirm my assumption about PHP array indexes being case-sensitive.
http://stackoverflow.com/questions/1511230/php-array-are-array-indexes-case-sensitive

Yep, added the check for all cases and database insert worked! Yay!!

I wonder what other languages treat array indexes as case-sensitive? Maybe all programming languages? This would only make sense, no? The value of an index is calculated differently based on char value, right?

To be continued...

Happy Coding,
G2