note 104465 deleted from book.array by danbrown
| From: | danbrown@php.net | Date: | Thu, 16 Jun 2011 17:01:48 +0000 |
| Subject: | note 104465 deleted from book.array by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-180622@lists.php.net to get a copy of this message | ||
Note Submitter: Ray.Paseur Gmail
----
The comment here is factually inaccurate:
http://us2.php.net/manual/en/book.array.php#96219
PHP loose data typecasting is applicable to array keys, and if you use a numeric string for an array
key, you will get a numbered index. And it will overwrite any existing numbered index in the array.
This script outputs:
array(1) { [3000000000]=> bool(true) } array(1) { [3000000000]=> bool(true) }
<?php // RAY_temp_johnmarc.php
ini_set('display_errors', TRUE);
error_reporting(E_ALL);
// KEY AS INTEGER
$key = 3000000000;
$DATA[$key] = true;
var_dump($DATA);
// KEY AS INTEGER, BUT CAST AS STRING
$key = 3000000000;
$DATA["$key"] = true;
var_dump($DATA);