Extension talk:Arrays/archive

such a pragmatic extension thanks

Arraydefine
On your examples page you use something like

which would create an array 1,2,3. But it's not documented here yet. Is this an permanent feature allready? Are there more values for this parameter? --Danwe 22:13, 25 February 2009 (UTC)

Well, the feature has not yet been released because of some concerns on the design of function interface (users may want to set multiple values on the last parameter, e.g. make it unique, make it sort). would it be natural to use '&' to separate the values? - Lidingpku 14:04, 17 March 2009 (UTC)
 * I don't know, I personal wouldn't use & but there could be reasons to do so. I like the last parameter to sort or unique in the same step and I already use this feature. --Danwe 20:41, 25 April 2009 (UTC)


 * Ok, the option (unique, sort, and print) has been added in version 1.2.1 -- Lidingpku 15:39, 3 May 2009 (UTC)

Arrayreset
I think #arrayreset is not very hepful in it's actual function. In most cases I have a template where I create a temporary array and I want to destory it there. But when you use  there, it will destroy ALL arrays, also these which were not defined in that template which are still needed in some cases. So perhaps it would be better if you could use that function #arrayreset alternatively like that:  or even better:. Shure, you can also use but I think it would be more pretty if you could use the #arrayreset function because you can see on first fiew where an array is going to be defined and where it will be destroyed. --Danwe 22:22, 25 February 2009 (UTC)

ok, one option has been added to #arrayreset to support this idea. you can now use to unset a selection of arrays. - Lidingpku 14:28, 17 March 2009 (UTC)

Bug in Arrayresets if no arrays are defined before
If you use #arrayreset before you have defined a array before, you will get a error on the top of the page (but only on the preview page). Sometimes I reset arrays on the beginning of a template because I need to reset some template internal arrays. If the template is used on the top of the page this creates an error on the preview page. --Danwe 14:57, 18 May 2009 (UTC)

Arrayslice
I'm using arrayslice and am using 1 and 10 for the offset and length - then I am using arrayprint to post the 10 values in the new array. The extension is correctly posting 10 values; however, the array is starting with the second value of the array rather than the first. I have tried to post with an offset of zero and have even posted an arrayprint with an arrayslice with no length - the first value still doesn't show. Is this a bug, or am I doing something wrong?
 * Looks like they fixed that problem yesterday. Please youse the signature for the next time you add something to the talk page! --Danwe 20:39, 25 April 2009 (UTC)

I found another bug in arrayslice: This should return an void array because there are only 3 items inside the array. But instead of a void array the function returns the whole array. This is a problem with using variable parameters where you don't know before if the offset is bigger as the values. The bug appears for offsets >= arraysize. --Danwe 16:47, 28 April 2009 (UTC)


 * it has been fixed in version 1.2.1, Lidingpku 15:55, 3 May 2009 (UTC)

Arrayindex
If the arrayitem with the index doesn't exist or the index has an void entry, it should be possible to get an alternative value by adding this value as third parameter like:.

By the way, I need to know if an array exists to cache the content of an array for a template so save some time. I do thant in many templates. --Danwe 19:26, 7 May 2009 (UTC)

zero bug in arraydefine and arrayunique!
I was going to be crazy because I couldn't find a bug in my template. Finally I recorgnized this bug isn't in my template, it must be a ArrayExtension bug...

This bug is very strange. Whenever you have a zero "0" in your Array it happens. Arrayunique removes the "0" zero value! Even so does the unique command in Arraydefine. But that's not the only thing. When you define  you get a void array with #arraysize = 0. BUT if you have  the #arraysize is 2 and the "0" is in the array. But only as long as you don't run an #arrayunique on the array. This will remove the "0" again.

I don't know if there are any other functions which have the same effect on the zero. Arrayslice for example works well with zeros. Hope you can fix this bug soon. Actually I have some number arrays where zeros can appear as well. --Danwe 14:08, 17 May 2009 (UTC)


 * it has been fixed in version 1.2.2, Lidingpku 15:35, 16 July 2009 (UTC)


 * Looks like by fixing that bug, another bug came up in version 1.2.2 I think:
 * will print: . The 0 works now thankfully but what's doing the void value there? The documentation for arrayunique says: This function converts an array (identified by 'key') into a set (no duplicated members, no empty element). But actually, there is an empty element left. Is this the new behavior or simply a bug (what I would suggest)? --Danwe 12:54, 17 December 2009 (UTC)
 * A simple change in the code at line 392 to the code   would do the trick. --Danwe 13:24, 17 December 2009 (UTC)
 * Ok, it's fixed in version 1.2.3. Thanks! --Danwe 15:52, 18 December 2009 (UTC)
 * Ok, it's fixed in version 1.2.3. Thanks! --Danwe 15:52, 18 December 2009 (UTC)

New Functions
This extension looks really useful but it seems to be lacking a couple features, specifically functions to do push, pop, get and concat. The parserfunctions would look something like: - if key doesn't exist, it is created; direction indicates beginning or end; so you can do FIFO and FILO - pops the value from array and returns it, direction indicates beginning or end - returns the value at the indicated position, position could be positive or negative index.

-- BlindWanderer 16:00, 26 May 2009 (UTC)


 * arraypush, arrayconcat, arraypop are replaced by arraymerge and arrayslice
 * arrayget is covered by arrayindex (expect the negative index is not supported)
 * Lidingpku 16:31, 16 July 2009 (UTC)

Arrayprint a list
Is it possible somehow to create a list with arrayprint? I tried:

But that creates only one whole big list Entry and not four. The other three * don't end in list points, they stay as *

I also tried

Doesn't work as well. Any ideas? --Danwe 23:42, 13 October 2009 (UTC)


 * here is a work around:


 * Lidingpku 19:56, 17 December 2009 (UTC)
 * Lidingpku 19:56, 17 December 2009 (UTC)


 * Good idea. Work's even better with a nowiki tag so you won't even have the ugly span in your HTML output:


 * --Danwe 04:17, 26 December 2009 (UTC)
 * --Danwe 04:17, 26 December 2009 (UTC)

Some ugly warnings on page imports
I had to import many pages which are using ArrayExtension. I got hundrets of warnings, all because of preg_split in line 162 of ArrayExtension.php because of Compilation failed: nothing to repeat at offset xxx and because of Invalid argument supplied for foreach on line 463 of ArrayExtension.php --Danwe 12:32, 1 December 2009 (UTC)


 * what deliminator did you use? can you show me link to the example?
 * Lidingpku 19:58, 17 December 2009 (UTC)


 * Sorry I don't have the import.xml anymore. I imported more than hundred pages and some of the templates I imported are using ArrayExtension. What do you mean with deliminator? If you mean the deliminator for regex search: I use / for most and sometimes %. I will get you an example when the error occurs again. But it could also be that the error came up because a very bad bug in one of my templates which could lead to a regex in #arraysearch which is not valid. I fixed that bug now perhaps this was the source of the error in the first time... --Danwe 15:46, 18 December 2009 (UTC)

#arraydefine bug with non escaped chars
If you use characters or words with chars which have a meaning in preg regex you get a php warning and the #arraydefine doesn't work like expected. This could be solved easily by using the preg_quote php function in case the delimiter isn't a regex like expression.

You can also use the regex  to check whether the delimiter is a regex or not.

Example - this won't work:  (I use    with Semantic MW as seperator in Attribute values which contain informations I validate in templates on other pages per query)

--Danwe 21:43, 30 December 2009 (UTC)


 * This is working now. --Danwe 22:24, 26 January 2010 (UTC)

modifiers for regex #arraydefine
Today I tried to create a #arraydefine which splits a string on its line breaks like that: to split the sting on its line breakings. But it doesn't work because m and any other modifiers are ignored. Instead I have to use the much longer regex  to be sure that windows, mac and linux servers are compatible with the page. Especially the i modifier would be extremely helpful in many cases I can imagine. Enabling other characters as regex seperators than / would be nice as well. I often use % when I use many slashes inside my regex. --Danwe 22:42, 26 January 2010 (UTC)