#136808 - 2005-03-30 10:05 PM
Make JOIN() from left OR right.
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Just ran into a thingy where I could have used the following:
The Join() function takes a third optional (positive) number indicating the number of array elements to join (from the beginning of the array) ...
Was thinking would be nice to be able to specify a negative number, indicating that the join works from the end (or tail-end of the array), inward. Kinda like:
Code:
break on
$array = 1,2,3,4
?"val=" join($array, "-", 2) ; produces 1-2
?"val=" join($array, "-", -2) ; currently produces 1-2-3-4, maybe have it do 3-4 instead ?
Anyway - really could have used this today - I know there are ways to achieve the desired result without this, but since negative numbers in the third argument aint supported anyways, doesn't hurt to think aloud.
-Shawn
|
|
Top
|
|
|
|
#136811 - 2005-03-30 11:33 PM
Re: Make JOIN() from left OR right.
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
I had this come up a little while ago, where i only wanted the last X number of array items in a join statement.
joins a join($array,"-",-4) would have been better than this....
Code:
Function reversejoin($array,$d,$n) If UBound($array)-$n > -1 For $N = UBound($array)-$n To UBound($array) $reversejoin = "" + $reversejoin + $d + $array[$N] Next Else $reversejoin = Join($array,$d) EndIf If SubSTR($reversejoin,1,1) = $d $reversejoin = SubSTR($reversejoin,2) EndIf EndFunction
|
|
Top
|
|
|
|
Moderator: Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
0 registered
and 837 anonymous users online.
|
|
|