- 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.
Broken arrays
Broken arrays
I'll start with a short message.
-
admin
- Site Admin
- Posts: 64915
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Broken arrays
By "fix" you mean nice-to-have enhancements. It's not impossible that they'll come one day.
FAQ | XY News RSS | XY X
Re: Broken arrays
This is not an enhancement, associative arrays are useless:
and the lack of information in the Help makes arrays functionality hidden and incomprehensible.Instead of the index $I (0, 1, ..., $Len), the string key $I is created ("0", "1", ..., " len"). That's it, an associative array cannot be filled in a loop by index.
I understand that it will take time, so I will wait for their improvement. My goal was to remind you of these issues.
-
admin
- Site Admin
- Posts: 64915
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Broken arrays
Your example has syntax errors. Nothing is broken with arrays if you write correct code:
Code: Select all
$a['pussy']="cat";
$Len = 2;
for ($i=0; $i<$Len; $i++) {
$a[$i] = $i*10;
}
echo $a[$Len]; //10
echo $a[1]; //10
echo $a["1"]; //10
echo $a["pussy"]; //cat
FAQ | XY News RSS | XY X
XYplorer Beta Club