Q:

PHP Associative Array Looping in Twig

How can i loop this array in Twig ?
what im doing wrong ?
here is what i have
<?php foreach (array('price','weight','length','width','height','points') as $mod) { ?>
<label class="col-sm-2 control-label" for="input-<?php echo $mod . $option_row; ?>"><?php echo ${'text_option_'.$mod}; ?></label>
  <select name="product_option[<?php echo $option_row; ?>][value][<?php echo $mod; ?>_prefix]" class="form-control">
<option value=""<?php if (isset($product_option['value'][$mod.'_prefix']) && $product_option['value'][$mod.'_prefix'] == '') echo ' selected'; ?>>NONE</option>
<option value="+"<?php if (isset($product_option['value'][$mod.'_prefix']) && $product_option['value'][$mod.'_prefix'] == '+') echo ' selected'; ?>>+</option>
</select>

here is what i done but isnt work
{% for price, weight, length, width, height, points in mod %}
<label class="col-sm-2 control-label" for="input-{{ mod . option_row}}">{{ text_option_ . mod}}</label>
<select name="product_option[{{ option_row }}][value][{{ mod }}_prefix]" class="form-control">
<option value=""{% if product_option['value'][mod.'_prefix'] is defined and product_option['value'][mod.'_prefix'] == '' %} {% endif %} {{'selected'}}; >NONE</option>
<option value=""{% if product_option['value'][mod.'_prefix'] is defined and product_option['value'][mod.'_prefix'] == '+' %} {% endif %} {{'selected'}}; >+</option>
</select>
{% endfor %}

A:

You are building your array wrong. Also it's {% for needle in haystack %} in twig... So your first line should become:
{% for mod in [ 'price','weight','length','width','height','points' ] %}

