Code: Select all
v23.50.0015 - 2022-08-15 16:56
+ Scripting | Arrays: No new features, but completely rewritten with scalabililty and
future in mind. Some rules emerged along the way:
- Array elements also work within quotes:
$a[0] ="cat"; echo "It is a $a[0]!"; //It is a cat!
- If the index or key is invalid the variable is seen just as a bit of text:
$a[0] ="cat"; echo "It is a $a[1]!"; //It is a $a[1]!
$a["pussy"] ="cat"; echo "It is a $a['fussy']!"; //It is a $a['fussy']!
- Also a missing key makes the variable invalid:
$a[0] ="cat"; echo "It is a $a[]!"; //It is a $a[]!
- Allowed range of elements per array: 0 to 32767 (= 32768 max for assoc arrays).
This limit is arbitrary. I just had to give it some limit.
- Array variables and normal variables with the same base name can be used side by
side like different variables:
$a ="cat"; $a[0] = "dog"; echo $a; echo $a[0]; //"cat", "dog"
$a[0] ="cat"; $a = "dog"; echo $a[0]; echo $a; //"cat", "dog"
But they share the same perm/global properties, so think of this $a as $a[-1],
as just one more place to store a value in.
- If you assign a non-first element in a new or smaller indexed array, all previous
elements starting with [0] are automatically created (with value ""):
$a[1] ="cat"; echo $a[0]; //"" ($a[0] is implicitly created and set to "")
$a[0] ="cat"; echo $a[1]; //$a[1] ($a[1] does not exist as variable)
- The global command is supported by arrays. Just like with normal variables the
global command must be used in the source and the target location (it's weird but
I copied that from PHP years ago):
"_Initialize"
global $a[0] = "Hi!";
global $a[1] = "Bye!";
$a[2] = "Uhm"; //not global, won't work below
"Say Hi"
global $a[0];
echo $a[0]; //"Hi!"
"Say Bye"
global $a[1];
echo $a[1]; //"Bye!"
"Say Uhm 1"
global $a[2];
echo $a[2]; //""
"Say Uhm 2"
echo $a[2]; //$a[2]
"_Terminate"
global $a[1];
echo $a[1]; //"Bye!"
- The perm command is not supported by arrays but is simply ignored: Arrays cannot
be permanent.
- No performance tests have been done yet, but I wouldn't expect miracles. Larger
arrays will likely be damn slow.
>>> There have been some RADICAL CHANGES in scripting related code. Test with CARE!
XYplorer Beta Club