Discussion:
Can I use strings with some unicode characters as array keys?
Andre
2011-07-31 02:07:03 UTC
Permalink
Question to someone who's familiar with how arrays are implemented in PHP.
I've been researching this for couple of hours but my C level is still
a bit low.
PHP manual says that one should only use strings or integers as keys.
Also I know that PHP doesn't speak unicode yet.
So - I was just wondering - when unicode characteres aare used in
array key - does PHP strips them or affects them in any way?
or does iPHP simply treats keys as binary string, the end of the story?

Can I use strings with some unicode characters as array keys?
--
PHP Unicode & I18N Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Darren Cook
2011-07-31 03:16:16 UTC
Permalink
Post by Andre
PHP manual says that one should only use strings or integers as keys.
Also I know that PHP doesn't speak unicode yet.
Depending on what you mean by speaking unicode; the mbstring extension
has worked well for everything I've ever needed to do with unicode, and
supports all the various unicode character sets.
Post by Andre
So - I was just wondering - when unicode characteres aare used in
array key - does PHP strips them or affects them in any way?
I believe that string array keys are treated as binary strings, and
never modified. I couldn't find you a source, but I've always worked on
this assumption and never hit a problem. UTF-8 keys definitely work fine
(*); I'm also not aware of any max length the keys can have (meaning you
shouldn't have to worry about a multi-byte character getting truncated
in the middle).

Darren

*: Well, to fully qualify that, I may only ever have tried with
Japanese, Chinese, Arabic and European languages :-)
--
Darren Cook, Software Researcher/Developer

http://dcook.org/work/ (About me and my work)
http://dcook.org/blogs.html (My blogs and articles)
--
PHP Unicode & I18N Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Darren Cook
2011-07-31 03:27:26 UTC
Permalink
Post by Darren Cook
(*); I'm also not aware of any max length the keys can have (meaning you
shouldn't have to worry about a multi-byte character getting truncated
in the middle).
It seems max key size is the script's memory limit:

http://stackoverflow.com/questions/467149/what-is-the-max-key-size-for-an-array-in-php

Darren
--
Darren Cook, Software Researcher/Developer

http://dcook.org/work/ (About me and my work)
http://dcook.org/blogs.html (My blogs and articles)
--
PHP Unicode & I18N Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...