Associative arrays

Things you’d like to miss in the future...
Forum rules
:warnred20: :warnred20: :warnred20: :warnred20: :warnred20: READ THIS AND DO IT!!! :warnred20: :warnred20: :warnred20: :warnred20: :warnred20:

:info: Please include the following information:
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).

:info: We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.

:info: When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".

:warnred20: :warnred20: :warnred20: :warnred20: :warnred20: READ THIS AND DO IT!!! :warnred20: :warnred20: :warnred20: :warnred20: :warnred20:
Post Reply
altoclef
Posts: 99
Joined: 12 Oct 2012 18:54
Location: Win11 24H2 @100%

Associative arrays

Post by altoclef »

From the Scripting > Arrays section in the help:
If the index or key is invalid the variable is seen just as a bit of text:

Code: Select all

$a["pussy"] = "cat";
    echo "It is a $a['fussy']!"; //It is a $a['fussy']!
However, if the empty array is created first:

Code: Select all

$a = array(); 
    $a["pussy"] = "cat";
    echo "It is a $a['fussy']!"; //It is a cat!
Have I misunderstood something or is the output incorrect?

[EDIT: Forgot to add my XY version. I'm on 27.20.1000.)

admin
Site Admin
Posts: 66075
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Associative arrays

Post by admin »

$a = array(); makes it implicitly non-associative. All string indices are then converted to number 0 (zero). I agree that this is a bug and it should be fixed. Raise your voice now if you think otherwise.

altoclef
Posts: 99
Joined: 12 Oct 2012 18:54
Location: Win11 24H2 @100%

Re: Associative arrays

Post by altoclef »

Confirmed fixed in v27.20.1004.
Thank you. :tup:

Post Reply