Re: Can I use strings with some unicode characters as array keys?
| From: | Lars Schultz | Date: | Sun, 31 Jul 2011 07:34:57 +0000 |
| Subject: | Re: Can I use strings with some unicode characters as array keys? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-54259@lists.php.net to get a copy of this message | ||
Hi Andre,
You could've just tried it yourself;)
$list = array(
'a'=>'string key',
utf8_encode('ä')=>'unicode key', //will be treated as an ascii-string
10=>'int key',
2.2=>'float key', //will be cast to an int(2)
null=>'null key', //will be cast to a string(0) ""
true=>'boolean key', //will be cast to an int(1)
);
class B { }
$f = fopen('/tmp/x','r');
$list[$f] = 'resource key'; //$f will be cast as an int(x)
$list[new B()] = 'object key'; //yields an "illegal offset type" notice
foreach( $list as $key => $value ) {
echo $value .': ';
var_dump($key);
}
Am 31.07.2011 04:18, schrieb Andre:
Question to someone who's familiar with how arrays are implemented in PHP. I've tried asking this on stackoverflow.com, but it looks like I need to ask this one to people familiar with PHP source. PHP manual says that one should only use strings or integers as array keys. Also I know that PHP doesn't speak unicode yet. So - I was just wondering - when unicode characteres are 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? Thank you!