Let's say I define an array:
$a = Array();
$a[0] = 1;
$a['0'] = 2;
$a['0a'] = 3;
print_r($a);
Conclusion of the expected result. I suppose there is something like strval()or inside intval()to allow overwriting the value.
Array
(
[0] => 2
[0a] => 3
)
But this is what bothers me.
foreach($a as $k => $v) {
print(gettype($k) . "\n");
}
This gives me:
integer
string
How is it that PHP does these type conversions when using Array keys? that is, how to determine the key is a "real decimal integer" according to the documentation? Also is_intdoes not work with strings.
source
share