CalcBuilder Forum

Decipher a code

User moon_842 2012-12-31 03:29:18

I'm trying to understand this code I grad from your "Estimate business card" example. Can you please explain this?:

for ($i = 1; $i

Moonsoft support 2012-12-31 09:41:18



for ($i = 1; $i


Hello,

This is a conditional statement mostly used to go through an array(list) of elements. In calcbuilder you can use it to get elements with more than one value from form. For example, if you use a "multiple option" field with "var" name 'multiple' , you can see in form checkboxes to select. You can use 'multiple' values in 'code' as array. To get all values separated with commas you could use 'for' structure like this:

$multiple_values='';
for($i=0;$i' is to apply number format to them

for ($i = 1; $i r$i"."1,2);");
}


First we declare for only for 5 elements, because it´s the number of vars we have.

for ($i = 1; $i te '$var' as string with $i from the loop and '1', so in first step the result will be $var11, in next step $var21 and so on. This variable (the same we declare before loop) is assigned to the result of number format function.

eval("\$var$i"."1=number_format(\$var$i"."1,2);");


This 'for' statement is the shortcut for doing this:
$var11=number_format($var11,2);
$var12=number_format($var12,2);
$var13=number_format($var13,2);
$var14=number_format($var14,2);
$var15=number_format($var15,2);


Hope this helps. Regards,

Editado por MSTeam - 31.12.2012 09:43

...
Support/development 40 hours

With the peace of mind of having a professional team at your service (20% discount)

Buy now!
...
CalcBuilder

Create dynamic calculators

Buy now!