PHP Code:
/*
Scripted by Chompy v0.1
*/
public function array(a) {
this.array = a;
return this.array;
}
public function debug() {
return this.array;
}
public function debug2() {
echo(this.array);
}
public function sub(s, e) {
return this.array.subarray(s, e > 0 ? e : -1);
}
public function getsize() {
return this.array.size();
}
public function getindices(v) {
temp.out = 0, temp.i = 0;
for(temp.m : this.array) {
if (m == v) out.add(i);
i ++;
}
return out;
}
public function addlist(a) {
if (a.type() == 3) {
for(temp.m : a) {
this.array.add(m);
}
}
}
public function hasvalue(v) {
return (this.array.index(v) > -1);
}
public function hasindex(i) {
return (this.array[i] != NULL);
}
public function addvalue(v) {
this.array.add(v);
}
public function removevalue(v, mode) {
while(this.array.index(v) > -1) {
this.array.delete(this.array.index(v));
if (!mode) break;
}
}
public function removeindex(i) {
if (i < this.array.size()) this.array.delete(i);
}
public function addindex(i, v) {
this.array.insert(i, v);
}
I was kinda inspired by Knight's Associative array code (
http://forums.graalonline.com/forums...ad.php?t=68643),
so I decided to make my own :o This is just the first version, alot more functions will come, so suggestions would be nice
Example of usage:
PHP Code:
function onCreated() {
this.object = new TStaticVar();
this.object.join("util_array"); // change this to the class you putted the code into
echo(this.object.array({"foo", "bar"})); // creates the array and echoes it
this.object.addlist({"baz", "baz", "baz"}); // adds a list of members to the array
this.object.debug2(); // echoes the current array
echo(this.object.sub(2)); // works like obj.subarray()
echo(this.object.hasvalue("bar")); // if the array contains "bar"
echo(this.object.getindices("baz")); // obj.indices
echo(this.object.addindex(2, "lol")); // obj.insert
echo(this.object.removeindex(1)): // obj.delete
echo(this.object.addvalue("lol")); // obj.add
echo(this.object.getsize()); // obj.size()
// etc.
}
And again, will work on it, so suggestions for functions/things I could add would be nice
