Array array type analysis in PHP
- 2020-03-31 21:02:59
- OfStack
PHP's array keys can be of type string or integer. If the key is a float, it is automatically converted to an integer.
If a key is not specified for a value, the maximum value of the index of type integer is given, and the new key is the maximum value plus 1. If the new key has been assigned, the value will be overwritten.
The result of the above code is
It looks like this. Only so there is no value "d" because he is followed by 6=> The 'g' is overwritten
If a key is not specified for a value, the maximum value of the index of type integer is given, and the new key is the maximum value plus 1. If the new key has been assigned, the value will be overwritten.
<?php
$arr = array('a','b',5=>'c','d','e',6=>'g');
echo '<pre>';
print_r($arr);
echo '</pre>';
The result of the above code is
Array(
[0] => a
[1] => b
[5] => c
[6] => g
[7] => e)
It looks like this. Only so there is no value "d" because he is followed by 6=> The 'g' is overwritten