Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision |
en:create:variables [05.02.2015 21:02] – [Use with Urns] alexander.ritter | en:create:variables [05.02.2015 21:06] – [Use Variables Continuously] alexander.ritter |
---|
===== PHP Variables ===== | ===== PHP Variables ===== |
| |
In PHP, variables start with a dollar sign, e.g. ''$version''. A value is assigned to the variable with a single equals sign (''=''). This value is compared with another value with a double equals sign (''==''). | In PHP, variables start with a dollar sign, e.g. ''$version''. A value is assigned to the variable by using a single equals sign (''=''). This value is compared with another value by using a double equals sign (''==''). |
| |
**Note:** A PHP variable is only valid within a //PHP code// element. It is transient, and therefore will not be stored permanently. If you want to use the variable later on in other PHP code elements, the variable therefore has to be made available by using ''[[:en:create:functions:registervariable|registerVariable()]]''. If the value of the variable is needed for the analysis, it has to be stored in an internal variable by using ''[[:en:create:functions:put|put()]]''. | **Note:** A PHP variable is only valid within a //PHP code// element. It is transient, and therefore will not be stored permanently. If you want to use the variable later on in other PHP code elements, the variable therefore has to be made available by using ''[[:en:create:functions:registervariable|registerVariable()]]''. If the value of the variable is needed for the analysis, it has to be stored in an internal variable by using ''[[:en:create:functions:put|put()]]''. |
==== Working with Variables ==== | ==== Working with Variables ==== |
| |
Variables allow you to calculate superbly. In the following example, the participant is asked question "AB01" on page 1 -- a text input for a number. The response is read on page 2 using ''value()'' and stored in the variable ''$number''. This variable it multiplied by 2 (''*'') and the result is stored in the variable ''$result''. | Variables allow you to calculate superbly. In the following example, the participant is asked question "AB01" on page 1 -- a text input for a number. The response is read on page 2 using ''value()'' and stored in the variable ''$number''. This variable is multiplied by 2 (''*'') and the result is stored in the variable ''$result''. |
| |
Subsequently, the variable ''$result'' is treated as text (string) and linked with two other string (''.''). The result of this link is transferred to the function ''html()'' to display in the questionnaire. | Subsequently, the variable ''$result'' is treated as text (string) and linked with two other string (''.''). The result of this link is transferred to the function ''html()'' to display in the questionnaire. |
It makes sense that the stations are queried in the same order in both questions. In order to do so, first of a list ([[:en:create:array|Array]]) of the item IDs in a random order is created using ''[[:en:create:functions:random_items|random_items()]]''. This list is stored in the variable ''$items''. | It makes sense that the stations are queried in the same order in both questions. In order to do so, first of a list ([[:en:create:array|Array]]) of the item IDs in a random order is created using ''[[:en:create:functions:random_items|random_items()]]''. This list is stored in the variable ''$items''. |
| |
The variable ''$items'' is not only needed on the current page, but on the following page for question "AB02" as well. Theefore, this is made available for future PHP code elements using ''[[:en:create:functions:registervariable|registerVariable()]]''. Subsequently, question "AB01" will be displayed with the shuffled order. | The variable ''$items'' is not only needed on the current page, but on the following page for question "AB02" as well. This is therefore made accessible for future PHP code elements using ''[[:en:create:functions:registervariable|registerVariable()]]''. Subsequently, question "AB01" will be displayed in the shuffled order. |
| |
<code php> | <code php> |