This function
function convert($size) {
$unit = array(
'B',
'KByte',
'MByte',
'GByte',
);
return round($size / pow(1024, ($i = floor(log($size, 1024)))), 2) . ' ' . $unit[$i];
}
works but PHPStorm says
Illegal array key type on line 54
that means $unit[$i].
What's wrong with this function?
floorreturns a float, and using a float as an array key is usually a no-no. Be advised that some other functions, likearray_key_exists, will actually produce a runtime error if you pass that$ias the key, based solely on its type.$i?($i = floor(...