Re: Append variable to an array ?
Posted: 27 Dec 2023 17:04
And stop mailing me.
Forum for XYplorer Users and Developers
https://www.xyplorer.com/xyfc/
implode()?I wanted to as you mentioned here; viewtopic.php?p=216791#p216791 to append a variable to an array. Therefore I append each iteration to the the array and that is $pArray[$i]=$iten then using implode I want to show the array as this function does and that is what I want to do. When implode() function was not just returning the array but also the function itself I wanted to know what I'm doing wrong.highend wrote: ↑27 Dec 2023 20:37 Maybe, just maybe... You read up the syntax ofimplode()?
The second parameter is the variable name of the list to map the array to.
Does it make sense to use $i (the iterator) here?...
Why is "||" used as the separator, you aren't even assigning $gPath to the array but a single folder name, etc. etc. etc.
$askusr does only contain (at max) one)$iten the goto will failimplode() is totally unnecessary (and wrong!), the array doesn't even contain "||"-separated entriestext $pArray[0] as well$iten would really contain more than one item you would destroy your loop when implode() maps the array to the iterator because with the next loop $i wouldn't contain it's former number anymore (you just overwrote it via implode()^^)...Code: Select all
$askusr = inputfolder("C:\","Choose Source Folder");
$pArray[0] = $askusr;
text implode($pArray);
<allitems> does return what's currently inside the active pane, this has nothing to do with a "selection" and it would require a loop to get only the pure folder names from itI understand what your saying, including some of my mistakes. Although if one folder is selected and that folder contains sub-folders; I want to loop over those sub-folders ignoring any panes.highend wrote: ↑28 Dec 2023 08:06 Turn on Menu - Scripting - [x] Syntax Checking
You see garbage (and not the content of the array) because the implode() line is missing the trailing semicolon^^
Apart from that the whole script doesn't make sense
- Looping over a single item ($askusrdoes only contain (at max) one)
- If there are multiple subfolders in$itenthegotowill fail
- Theimplode()is totally unnecessary (and wrong!), the array doesn't even contain "||"-separated entries
you could just have usedtext $pArray[0]as well
- If$itenwould really contain more than one item you would destroy your loop whenimplode()maps the array to the iterator because with the next loop$iwouldn't contain it's former number anymore (you just overwrote it viaimplode()^^)...
It equals to (if I remove the unnecessary stuff) to:Code: Select all
$askusr = inputfolder("C:\","Choose Source Folder"); $pArray[0] = $askusr; text implode($pArray);<allitems>does return what's currently inside the active pane, this has nothing to do with a "selection" and it would require a loop to get only the pure folder names from it
Then use aI want to loop over those sub-folders ignoring any panes
foreach loop for the $ccPath?Code: Select all
$ccPath = listfolder($iten,input("Folder to Find",,,e,300,300),2,||);listfolder() is ||...input() part...listfolder() returns only the folders inside $iten...Code: Select all
$pArray[] = $ccPath$i=0; is initialized outside of the forEach loop, within the forEach I have $i+=1 and $ccPath does show the list of folders when returned then why since I'm assigning $ccPath to the array can I not just access one of the file paths using an Array index ?
Code: Select all
$ccPath = listfolder($iten,*,2,||);
$pArray[$i] = $ccPath;
}