This translation is older than the original page and might be outdated. See what has changed.
Translations of this page:
 

Table of Contents

infoVars()

array infoVars(string|array variableNames)

The function infoVars() returns technical information about a variable in the dataset. This function is particularly useful if you want to work with (custom) variable names when programming a questionnaire and need the corresponding item IDs.

  • string variableNames – A single variable name.
  • array variableNames – A list of multiple variable names.

Return Value

The function always returns an array that uses the given variable name(s) as keys and contains either an array with information or (if no variable was found under that name) null.

The contained arrays include the following information:

  • label – The “technical” name of the variable, consisting of the question ID and, if applicable, an appendix.
  • question – The ID of the question the variable belongs to.
  • item – The numeric ID of the item within the question or (if the variable does not belong to an item) null.
  • index – The index of the variable within the question or within the item, starting at 0.

Example

The following PHP code determines the corresponding item IDs from a list of variables in order to display them in the question AB01. Here, all variables belong to the question AB01.

$question = 'AB01';
$vars = ['genAlpha', 'genGamma', 'genEpsilon'];
$items = [];
foreach (infoVars($vars) as $info) {
  if ($info['question'] == $question) {
    $items[] = $info['item'];
  }
}
question($question, $items);
en/create/functions/infovars.txt · Last modified: by 127.0.0.1
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki