Hello,
I have made a pretty neat function that replaces a value from inside of a string to another value. This would have worked great, but for some reason, it's not returning the correct value. I have echoed the value before it is returned, and that value is correct, but it will not work for the return.
PHP Code:
function onCreated() {
echo(replaceVal("Testing-123-456","-", "huh"));
}
function replaceVal(temp.string, temp.oldval, temp.newval) {
temp.xa = 0;
for(temp.val = 0; temp.val < temp.string.length(); temp.val++) {
temp.arr = null;
temp.arr.add(temp.string.substring(temp.val, temp.oldval.length()));
for(temp.val2 = 0; temp.val2 < temp.arr.size(); temp.val2++) {
if(temp.arr[temp.val2] == temp.oldval) {
temp.newstring = temp.string.substring(0, temp.val) @ temp.newval @ temp.string.substring(temp.val + temp.oldval.length());
temp.xa++;
}
}
}
if(temp.xa > 1) {
replaceVal(temp.newstring, temp.oldval, temp.newval);
}
else {
echo(temp.newstring); //Correctly echoes Testinghuh123huh456
return temp.newstring; //Does not return Testinghuh123huh456
}
}
This -should- have returned Testinghuh123huh456. It echoes correctly as I said in a comment in my script too.
Thanks in advance for helping me
