The following is a summary of PHP array numeric key names:
The length of the key name can only be within the int length range. If it exceeds the int range, confusion such as overwriting will occur
When the key name length is int range, PHP will force the numeric key name to be converted into int numeric type
When the numeric key name is longer than 19 digits, it will become 0
When the key name is of normal length, the string or numerical type is the same
$i = 126545165; $arr['126545165'] = 'abc'; $arr[126545165] = 'uio'; var_dump($arr); echo '<br>'; var_dump(isset($arr[$i]));
When the length exceeds an integer, the key name will be confused<喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PHByZSBjbGFzcz0="brush:java;">$i = 12312312312312;
$arr['1000000000147483649'] = 'abc';
$arr[1000000000147483649] = 'uio';
var_dump($arr);
echo '
';
var_dump(isset($arr[$i]));
When the length exceeds 20 characters, the key name will become 0
$i = 123123123123123123123123123123; var_dump($i); echo '<br>'; $arr[123123123123123123123123123123] = 'abc'; $arr[strval(123123123123123123123123123123)] = 'abc'; var_dump($arr); echo '<br>'; var_dump(isset($arr[$i])); echo '<br>'; var_dump(isset($arr[strval($i)])); echo '<br>'; var_dump(array_keys($arr));
Accessing variables directly as key names has different results
$i = 123123123123123; var_dump($i); echo '<br>'; $arr[$i] = 'abc'; $arr[strval($i)] = 'abc'; var_dump($arr); echo '<br>'; var_dump(isset($arr[$i])); echo '<br>'; var_dump(isset($arr[strval($i)])); echo '<br>'; var_dump(array_keys($arr));
Judging from the above tests:
If the key name is a number and the range is within int, string or int will not have any impact on access
If the length is greater than int, it will be automatically converted to float. Then conversion and access will cause various confusions, or even directly become 0, so it is best to uniformly convert to string type
$i = 123123123123123123123123123123; $j = '123123123123123123123123123123'; $arr1[strval($i)] = 'abc'; $arr2[$j] = 'abc'; var_dump($arr1); echo '<br>'; var_dump($arr2);
So when dynamically operating a PHP array, if you are not sure whether the key name will contain numbers or the length is greater than int, it is most secure to uniformly convert the key name strval to a string for operation