To array definitions
To array definitions
This is like "my expectation" of things - so in "Wishes".
If I interpret your definition of "global arrays" correct, it's the wrong name. As it seems you don't define the array as global, but distict array elements.
For me this looks *very* strange. Results in an array where parts are global and others are not - to me this almost seems like two different arrays.
I'd generally expect that an array as a whole is to be defined global. Like "global array[];"
If you won't: please allow something like "global array[*];"
If I interpret your definition of "global arrays" correct, it's the wrong name. As it seems you don't define the array as global, but distict array elements.
For me this looks *very* strange. Results in an array where parts are global and others are not - to me this almost seems like two different arrays.
I'd generally expect that an array as a whole is to be defined global. Like "global array[];"
If you won't: please allow something like "global array[*];"
Win11 Pro 223H2 Gerrman
Re: To array definitions
+1 While i was reading changelog, i totally missed the right logic at examples with numerous stating that separate array elements are global, and most of when array element was stated as global for second time though it was already before.
There should be a need of one time stating array being global, and any mention later in any section of same script file should treat it as global. No perm is not a big deal, each array can be saved by user individually in mere txt file.
There should be a need of one time stating array being global, and any mention later in any section of same script file should treat it as global. No perm is not a big deal, each array can be saved by user individually in mere txt file.
Win 7 SP1 x64 100% 1366x768
-
- Site Admin
- Posts: 60564
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: To array definitions
Totally right, of course. Let me try again...
FAQ | XY News RSS | XY Twitter
-
- Site Admin
- Posts: 60564
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: To array definitions
Next beta:
Code: Select all
"_Initialize"
global $a[];
$a = "I am Groot!"; //root variable
$a[0] = "Hi!";
$a[1] = "Bye!";
"Say Hi"
global $a[];
echo $a[0];
"Say Bye"
global $a[];
echo $a[1];
"_Terminate"
global $a[];
echo $a;
FAQ | XY News RSS | XY Twitter
Re: To array definitions
Yes,
But to be honest, I didn't get the "root variable" thing yet. Is that an additional slot in the array?
Re: To array definitions
I have never heard about that either. I mean, from array point of view. Actually it might be good for storing some description of the whole array.
Re: To array definitions
Another thing. (I react early, before it's too late...)
You write, for example:
- an index to be 7 or a variable containing the same
- an index to be 'name' or "name" (with dflt rules like anywhere) or a var
- the same for values. Be it initialization or normal setting.
This way nobody has to learn (and differentiate) other syntax.
I hope you understand what I want to say.
You write, for example:
Sounds very strange! XY till now defines rather good, what Text, number, or variable is. For me: values (and indexes) should depend on the same definitions. So I'd expect:You can only pass literal strings as values, not variables.
- an index to be 7 or a variable containing the same
- an index to be 'name' or "name" (with dflt rules like anywhere) or a var
- the same for values. Be it initialization or normal setting.
This way nobody has to learn (and differentiate) other syntax.
I hope you understand what I want to say.
Win11 Pro 223H2 Gerrman
-
- Site Admin
- Posts: 60564
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: To array definitions
1) root variable: In other languages you get an error when you use an array variable without index. But XY can tolerate it the way it is built here. Think of it as an additional element.
2) You can only pass literal strings as values, not variables. AFAIK it is like that in PHP. But I'm not sure.
2) You can only pass literal strings as values, not variables. AFAIK it is like that in PHP. But I'm not sure.
FAQ | XY News RSS | XY Twitter
Re: To array definitions
If this is for something like initialization (say in array()) I think it *might* be tolerated.
But if
Code: Select all
a[1] = $var;
a[$nr+3] = $other * 4;
In other words: the index [...] and the value should just be normal expressions as elsewhere, and all is fine.
For me an array is nothing but a group / list of variables, belonging together, and often being worked on by index or key.
Win11 Pro 223H2 Gerrman
Re: To array definitions
Yeah, I guess expressions are mandatory.
For example if you want to create an associative array by parsing a structured text file (e.g. a .ini). Not possible without expressions / variables...
For example if you want to create an associative array by parsing a structured text file (e.g. a .ini). Not possible without expressions / variables...
One of my scripts helped you out? Please donate via Paypal
Re: To array definitions
Actually I also misunderstood it first. This "literal" stuff is only for the array() command. If you want to fill up the array by that command, you have to know the values in advance. Otherwise you can use variables.PeterH wrote: ↑16 Aug 2022 15:19If this is for something like initialization (say in array()) I think it *might* be tolerated.
But ifwouldn't be ok - I think I wouldn't need arraysCode: Select all
a[1] = $var; a[$nr+3] = $other * 4;
In other words: the index [...] and the value should just be normal expressions as elsewhere, and all is fine.
For me an array is nothing but a group / list of variables, belonging together, and often being worked on by index or key.
Re: To array definitions
And nested arrays (with a nesting depth/dimension limit, if it is required) for (simple) tree-related "structures" (e.g., "value objects").
-
- Site Admin
- Posts: 60564
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: To array definitions
Coming...
Welcome to the happy world of nested arrays:
(preview of next beta)
Welcome to the happy world of nested arrays:
Code: Select all
$b[0] = "pus"; $b[1] = "sy"; $a[$b[0] . $b[1]] = "cat"; echo $a[$b[0] . $b[1]]; //cat
FAQ | XY News RSS | XY Twitter
Re: To array definitions
@me: should I rewrite some parts of my existing script lib?