Broken arrays
Posted: 11 Jan 2025 16:08
I'll start with a short message.
- Arrays (by array I will mean 1D, 2D, ..., arrays and associative arrays) cannot be returned from functions.
- It is not specified anywhere that an array can be passed to a function only if its argument is a reference to the array:
function func(&$array){}. It is not mentioned anywhere that an operator&is needed. - The Help File doesn't say anything about creating a fixed-length array e.g.
array[12]. But arrays can be filled in as simple C++ arrays:array[12]=value. - The index and values are interpolated/interpreted automatically, i.e. according to the Help, it is not necessary to use quotation marks in some cases:
$array[key] = "value", $arr = array(val1, val2, ...). Thats why associative array in the for loop is filled incorrectly:for ($I=0, $I<$Len, $I++) {$dict[$I] = $i }. Guess what happens? Instead of the index$I(0, 1, ..., $Len), the string key$Iis created ("0", "1", ..., " len"). That's it, an associative array cannot be filled in a loop by index.