Thank you for your mercy.
That's why I called
array()
a special function. It's a pseudo function that offers this particular way to fill an array.Thank you for your mercy.
array()
a special function. It's a pseudo function that offers this particular way to fill an array.Code: Select all
The new value-array loop is closer to how it's done in PHP:
General form value-array:
foreach($array as $value, [flags]) {
statement(s) using $value;
}
I don't want to over-push, but: with the new looping in mind, the inbuild scripting commands - with many of them returning
$Separator
-separated item lists (quicksearch(), regexmatches(), folderreport() etc.) - downright "scream" for a glueing handle (another special "constructor" function).Code: Select all
+ Scripting: Added special function arrayFrom() to create a zero-based indexed array from a "separated" list. Non-existing arrays
are created, dimensioned and populated, existing arrays are redimensioned and overwritten.
Syntax
arrayFrom(inputlist, [separator=" "], [flags])
inputlist: input list with separated items/elements.
separator: [optional] Separates the items in the returned list. Defaults to " ".
flags: [optional] placeholder
Notes:
- You can only pass a string as input, not arrays. The input "list" can be a single word w/o separator.
- If the input variable does not exist or is an "empty" string (aka "") the returned array has no element (array_count() == 0).
- The array values won't be quoted by default (see flags).
- If you like you can append [] to the variable, it makes no difference:
$a[] = arrayFrom(inputlist, [separator=" "], [flags]);
- The values are added to the array in the order of the input list, starting with element [0] (see flags).
Code: Select all
flags: (in any order)
"nd": "no dupes" - every entry of the resulting array is guaranteed to be unique. Once an input item/element already has been added the next input occurrence will be simply skipped.
"q": the array elements will be single quoted (q: what if they - by chance - already are?)
"r": the array will be build in reversed order.
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;
global $a[];
statements, you'll see it doesn't work.Yes, thanks for the well-crafted proposal. In PHP this function is called explode(): https://www.php.net/manual/de/function.explode.php And, of course, there is also the opposite: implode() (array -> list).
That is called multi-script in the help file. I can show you another example:eil wrote: ↑17 Aug 2022 00:22 That's probably dumb question, but i'm quite "only-with-help-file"-scripter, so i still don't understand- why so many times array stated as global? Isn't all this code part of one script, so after first statement it's global and ought to be same in all sub-scripts?..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;
Code: Select all
"Main_script"
global $a[];
$a = array("cat","dog");
echo $a[1]; //dog
sub "_another_script_hidden"
"_another_script_hidden"
global $a[];
echo $a[1]; //dog
global
means I want to use a global variable. If it doesn't exist, create it. If it does, get it for me .Code: Select all
"_Initialize"
perm $test = "a";
"hello"
echo $test;
"world"
echo $test;
"_Terminate"
unset $test;
I am sorry. Was it an anti-global post actually?highend wrote: ↑17 Aug 2022 10:32 You don't want to pollute the namespace with global variables...
And if you really want to have a "global" in another script, use perm (and reset it at the end)
Code: Select all
"_Initialize" perm $test = "a"; "hello" echo $test; "world" echo $test; "_Terminate" unset $test;
In the next beta this will work:admin wrote: ↑17 Aug 2022 10:24Yes, thanks for the well-crafted proposal. In PHP this function is called explode(): https://www.php.net/manual/de/function.explode.php And, of course, there is also the opposite: implode() (array -> list).
Needs some thinking though...
Code: Select all
syntax: count = explode($array, list, [separator="|"])
count = implode($array, $list, [separator="|"])
explode($a, "a,b,c", ","); echo $a[0]; $a[1] = "X"; implode($a, $list); echo $list; //a|X|c
Code: Select all
FYI:
If you do it with a non-associative array the key variable is not set in foreach
but remains whatever it is:
$key="KEY"; $a = array("cat", "dog", "bat"); foreach($a as $key => $value) {echo "$key: $value";};
Code: Select all
Error: 91 (0x0000005B)
Desc: Objektvariable oder With-Blockvariable nicht festgelegt
Dll: 0
Proc: script_Process: foreach
Source: XYplorer
XY ver: XYplorer 23.50.0019
OS: Windows 10 Enterprise, 64-bit, Release 2009, Build 19044.1766
Locale: 1033 (en-US)
ANSI: 0, ACP: 1252 (ANSI - Latin I)
Font: Segoe UI 8,25, Segoe UI 8,25, DBCS: No
DPI: 96 (100%), 3840x1600
Date: 2022-08-17 19:00:02
Code: Select all
$actions = <<<>>>
*\Bilder*|#308
D:\Users\%USERNAME%\Kontakte|load "@test.xys";
>>>;
foreach($item, $actions, <crlf>, "e") {
$path = gettoken($item, 1, "|");
}