Append variable to an array ?

Discuss and share scripts and script files...
MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Append variable to an array ?

Post by MonkeyButt »

How do I append a variable to an array; if it is at all possible ?

Code: Select all

foreach($iten,$askusr){
$ccPath = listfolder($iten,input("Folder to Find",,,e,300,300),2,||);
$pArray[] = array($ccPath);

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Append variable to an array ?

Post by highend »

Adding to an array is possible but it seems arrays can't contain subarrays...

Code: Select all

    $i = 0;
    foreach($iten,$askusr){
        $ccPath = listfolder($iten,input("Folder to Find",,,e,300,300),2,||);
        $pArray[$i] = $ccPath;
        $i += 1;
    }
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60619
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Append variable to an array ?

Post by admin »

:eh: I wonder why it shouldn't be possible, it's easy. I'll try it in the next beta.

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Append variable to an array ?

Post by highend »

Regarding the beta: This isn't any different from using explode() which worked already before that version?

That is not an array that is filled with other arrays (so called multi-dimensional arrays)...

For example (choose your own folder(s) which at least have one subfolder:

Code: Select all

    $folders = "D:\Users\Highend\Development\C#|D:\Users\Highend\Development\Dart";

    $i = 0;
    foreach($folder, $folders, "|", "e") {
        $subs = listfolder($folder, , 2, "||");
        explode($toAdd, $subs, "||", "e");
        $pArray[$i] = $toAdd;
        $i += 1;
    }
No, that doesn't work :masked:
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60619
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Append variable to an array ?

Post by admin »

It is fulfilling a very natural expectation. And array() can do some stuff that explode() can't.

Nope, multi-dimensional arrays are not supported.

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Append variable to an array ?

Post by highend »

It is fulfilling a very natural expectation
It was not the expectation from the op :biggrin:
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60619
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Append variable to an array ?

Post by admin »

Well, it was mine. :)

MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Re: Append variable to an array ?

Post by MonkeyButt »

highend wrote: 22 Dec 2023 17:18 Adding to an array is possible but it seems arrays can't contain subarrays...

Code: Select all

    $i = 0;
    foreach($iten,$askusr){
        $ccPath = listfolder($iten,input("Folder to Find",,,e,300,300),2,||);
        $pArray[$i] = $ccPath;
        $i += 1;
    }
👍 Except when I

Code: Select all

echo $pArray
no list is show ?

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Append variable to an array ?

Post by highend »

Implode the array to see all entries?
text implode($pArray);

or an index to see a specific one^^
One of my scripts helped you out? Please donate via Paypal

MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Re: Append variable to an array ?

Post by MonkeyButt »

highend wrote: 23 Dec 2023 01:49 Implode the array to see all entries?
text implode($pArray);

or an index to see a specific one^^
Impode() is sorta working, I'm getting the index value instead of the actual name of the folder ?

MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Re: Append variable to an array ?

Post by MonkeyButt »

Code: Select all

text implode($pArray,$i,||,,)
Result;

Code: Select all

implode(,0,||,,) goto B:\~~~~~
Why am I getting the function name in my output; I've read the function arguments half a dozen times I can't understand what I'm doing wrong ?

admin
Site Admin
Posts: 60619
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Append variable to an array ?

Post by admin »

Well, you have not read enough.

1) What do you want to achieve?
2) Show not just one line out of context but something that's copy-and-pastable for testing.

MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Re: Append variable to an array ?

Post by MonkeyButt »

admin wrote: 27 Dec 2023 11:58 Well, you have not read enough.

1) What do you want to achieve?
2) Show not just one line out of context but something that's copy-and-pastable for testing.
I want to show the list without the output showing the actual implode() function within the output.

Code: Select all

$i=0
foreach($iten,$askusr){
//$ccPath = listfolder($iten,input("Folder to Find",,,e,300,300),2,||);
$ccPath = listfolder($iten,*,2,||);
$pArray[$i] = $iten;
$gPath = pathreal($ccPath);
text implode($pArray,$i,||,,)
This is the output, the impode() function is also being put as the output ?
implode(,0,||,,) goto B:\Cloud\Sync\.autosave||B:\Cloud\Sync\DesignerPaths||B:\Cloud\Sync\FF~~~~~~~
I hope this helps.

admin
Site Admin
Posts: 60619
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Append variable to an array ?

Post by admin »

Cannot work with this. You're wasting my time. Sorry, I'm out.

MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Re: Append variable to an array ?

Post by MonkeyButt »

The script is not complete, I just wanted to know why I'm setting the implode() function in the printed output; doesn't make sense. I was hoping you would maybe know based on those lines of code. That is where the main problem exists; but if you want here is the whole code.

Code: Select all

$askusr = inputfolder("C:\","Choose Source Folder");
//$mvfld = input("Enter folder ",,,e,500,400); // Destination Folder for which the files are to be moved too from the Source Folder
$i = 0;
foreach($iten,$askusr){
//$ccPath = listfolder($iten,input("Folder to Find",,,e,300,300),2,||);
$ccPath = listfolder($iten,*,2,||);
$pArray[$i] = $iten;
$gPath = pathreal($ccPath);
text implode($pArray,$i,||,,)
goto $gPath;
$i += 1;
}

Locked