Dependency Graph

Dependency Graph
related to related to child of child of duplicate of duplicate of

View Issue Details

This bug affects 1 person(s).
IDProjectCategoryView StatusLast Update
08348Feature requestsExpression Managerpublic2016-04-30 19:58
ReporterDenisChenu Assigned To 
Status newResolutionopen 
Summary08348: Need some array function in EM
Description1st function : get the value of nth var in an array
2nd function : array_filter
Additional Information1st seems helping for me: acces to nth element of array : We can not use [3] in EM. Not find a good name ...

2nd: we already have countifop : but sumifop ? concateifop
(this last one can clearly be used with:
You answer implode(",",that.MULTI) in last answer

Better with
You answer implode(",",array_filter(that.MULTI)) in last answer
TagsNo tags attached.
Bug heat6


related to 07728 closedDenisChenu Bug reports Unable to use self.sgqa or this.sgqa 
related to 08571 closedDenisChenu Feature requests EM function : array_unique 
related to 11047 new Feature requests Enable RegEx for Relevance Equations 




2014-01-06 16:26

partner   ~27726

Arrays would also be a huge help for sorting issues like this: If you have a survey about health and ask related questions and there is a scoring question for each disease which calculates scores depending on the user's answers it would be very helpful to later sort these X different scores from MAX to MIN using EM to create an output like (disease/score):

1. Breast cancer: 75
2. AIDS: 69
3. Asthma: 61


2014-01-08 06:17

reporter   ~27752

Adding support for formal arrays would be much harder -- and if there was really a need for that, I'd recommend switching away from EM's Recursive Decent Parser and going to using Twig (extending Twig to support the needed EM functionality). Either way, formal arrays is likely to be a very large lift.

However, it is very easy to add new functions to EM.

Please say more about the features you are trying to add.

For example, the list() function is already designed to generate a comma separated list of non-empty answers. array_filter() may not be needed, because the "that.sq_XXX" notation lets you list all variables (or a subset of the variables) within a question.

As noted, we already have countifop() and sumifop(). Adding variants like concatenateifop() would be trivial.

As an alternate to adding arrays to EM, one option might be to make it easy to create and manipulate JSON from EM. Since JSON is just a string, as far as EM is concerned, someone could add functions to convert the JSON into arrays, hashes, etc. and implement functions like sort(), access the Nth value of an array, etc.

Another option is to implement the showAllResponsesExcept( questionList,attributeList,attributeTitleList) or showTheseResponses( questionList,attributeList,attributeTitleList) functions and add a sortBy option. That would solve Mazi's need, which is a very common reporting need.


2014-01-08 09:25

developer   ~27753

Aaaaaaaaah !!!

Don't know list ..... A great thanks for this ... implode is a bad example then.

I search a beter example [nth] , i need it somewhere (think it's for ranking question but maybe it's OK with existing function).

For JSON : if i don't make error : it's best to have same functionnality in PHP and in JS ?

Maybe i close this one and Add a sort specific. usort/uasort/sort etc ...

Maybe you rigth sortBy is the better system.



2014-01-08 11:33

partner   ~27759

Thanks for your detailed answer, Tom.

Can you explain how to exactly use the list() function? "Return comma-separated list of non-blank values" isn't very clear to me. For what requirements does it makes sense to make use of it?

As for the disease example I listed below: A simple sorting function might do the trick. If we use KEY => VALUE notation using question code as KEY and the score as value for sorting, maybe we can find some simple notation to refer to the KEY of a sorted array to be able to use something KEY.question for outputting sorted results within Limesurvey?!
Not sure if this makes sense at all...


2014-01-08 14:00




2014-01-08 14:02

developer   ~27764

@Mazi : uploade a test survey for list vs implode

I don't know if we have to have a Key->value function, think it can be great.

Maybe put another FR for sort and [key] ?

@Tom : did you think it's more clear if we put 2 new feature request : one for [key] and one for sort with example survey where it can be great ?


2014-01-08 15:58

developer   ~27767


But we can not use list with javascript actually ?

If i do :
var testArray=[{list(that.QQ)}] it make me and bad array.

And i can not have :
SQ1,SQ2,SQ5 for example (only code of sub question checked)

Issue History

Date Modified Username Field Change
2013-11-07 14:33 DenisChenu New Issue
2014-01-06 16:26 Mazi Note Added: 27726
2014-01-08 06:17 TMSWhite Note Added: 27752
2014-01-08 09:25 DenisChenu Note Added: 27753
2014-01-08 09:26 DenisChenu Relationship added related to 07728
2014-01-08 11:33 Mazi Note Added: 27759
2014-01-08 14:00 DenisChenu File Added: limesurvey_survey_listimplode.lss
2014-01-08 14:02 DenisChenu Note Added: 27764
2014-01-08 15:58 DenisChenu Note Added: 27767
2014-07-01 09:13 DenisChenu Relationship added related to 08571
2016-04-30 19:58 DenisChenu Relationship added related to 11047