The following is a summary of the PHP array numeric key names:
The length of the key name can only be within the int length range. If the value exceeds the int range, confusion such as overwriting will occur.
When the key name length is an int-range memory value, PHP will forcibly convert the number key name to an int numeric type
When the number key name length is greater than 19 digits, it will become 0
When the key name is of the normal length, the string or value type is the same
$i = 126545165;$arr['126545165'] = 'abc';$arr[126545165] = 'uio';var_dump($arr);echo '
';var_dump(isset($arr[$i]));
When the length exceeds the integer type, the key name is messy. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + PHByZSBjbGFzcz0 = "brush: java;"> $ I = 12312312312312; $ arr ['000000'] = 'abc'; $ arr [1000000000147483649] = 'uio '; var_dump ($ arr); echo'
'; Var_dump (isset ($ arr [$ I]);
If the length exceeds 20 bits, the key name will be 0.
$i = 123123123123123123123123123123;var_dump($i);echo '
';$arr[123123123123123123123123123123] = 'abc';$arr[strval(123123123123123123123123123123)] = 'abc';var_dump($arr);echo '
';var_dump(isset($arr[$i]));echo '
';var_dump(isset($arr[strval($i)]));echo '
';var_dump(array_keys($arr));
The variables are directly accessed as key names, and the results are different.
$i = 123123123123123;var_dump($i);echo '
';$arr[$i] = 'abc';$arr[strval($i)] = 'abc';var_dump($arr);echo '
';var_dump(isset($arr[$i]));echo '
';var_dump(isset($arr[strval($i)]));echo '
';var_dump(array_keys($arr));
From the above tests:
If the key name is a number and the value range is within int, the string or int does not affect access.
If the length is greater than int, it will be automatically converted to float, and then converted for access in various situations, or even directly changed to 0, so it is best to convert it to the string type in a unified manner.
$i = 123123123123123123123123123123;$j = '123123123123123123123123123123';$arr1[strval($i)] = 'abc';$arr2[$j] = 'abc';var_dump($arr1);echo '
';var_dump($arr2);
Therefore, when dynamically operating the PHP array, if you cannot determine whether the key name contains digits or the length is greater than int, it is the most secure to convert the key name strval to a string.