0 votes
in SoSci Survey (English) by s080412 (110 points)

Hello. I am constructing a survey where the participants will be tested on their memory of a set of faces and labels, compared to new faces and labels, and need to randomly draw the order/number in which old versus new will be shown in the test. How does one, in PHP, determine the odd or even value of an integer from an array? Sosci seems to not support the function:
if ($number % 2) {some html code}

but the code:
if ($number & 2 == 0) {some html code}

seems to get me no where. Help!

Here is the code from the page where the number is drawn (LI38 is the number draw questions).

$j = loopPage(30);
$numbergen = 'LI38x'.sprintf('%02d', $j +1);
$oldfaceID = 'LI19x'.sprintf('%02d', $j +1);
$newfaceID = 'LI19x'.sprintf('%02d', $j +30);
$oldlabelID = 'LI36x'.sprintf('%02d', $j +1);
$newlabelID = 'LI36x'.sprintf('%02d', $j +30);

$oldface = value($oldfaceID, 'label');
$newface = value($newfaceID, 'label');
$oldlabel = value($oldlabelID, 'label');
$newlabel = value($newlabelID, 'label');
if (value($numbergen) & 2) {
html('
<div style="float:right;">
<img src="'.$oldface.'.jpg" style="width:300px;"/>
</div>
<div style="width:300px;margin-bottom:250px;margin-top:200px;text-align:center;">
<p>'.$oldlabel.'</p>
</div>
'); }

else {
 html('
 <div style="float:right;">
 <img src="'.$newface.'.jpg" style="width:300px;"/>
 </div>
 <div style="width:300px;margin-bottom:250px;margin-top:200px;text-align:center;">
 <p>'.$newlabel.'</p>
 </div>
 '); }

LI19 and LI36 draw 60 values from 90 possible values, in which the first 30 (LI19x01 and LI36x01 through LI19x30 and LI36x30) are shown in an encoding phase.

1 Answer

0 votes
by SoSci Survey (328k points)

The code ($number % 2) works fine, it's just the code assistant of SoSci Survey that does not yet know the % operator. So, just use this one and ignore the warning below the PHP code.

However, I'm not so sure, if it's a good idea to work with odd an even numbers. If you randomize the order anyway, you could as well have the images sorted.

You may also consider using a "random generator" with two items (1 and 2 for "old" and "new") and draw e.g., 30 items per interview. Then you will have 30 variables (already stored in the data set!) containing 15 times 1 and 10 times 2. Just as an idea for optimization...

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen


Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

...