views:

67

answers:

1

Hi,

i want to show a select which options are the character '-' and a range of integers.

I have this:

$years = range(14,130);
new sfWidgetFormChoice(array('choices' => 
        array_merge(array('' =>  '-',array_combine($years,$years)));

The problem: between the '-' and the range of integers there is a "0" (bold and italic).

Any help?

Regards

Javi

+1  A: 

Oddly:

$years = range(14,20);
$foo = array("" => "-");
$bar = array_combine($years, $years);

$result = array_merge($foo, $bar);

gives:

array(8) {
  [""]=>
  string(1) "-"
  [0]=>
  int(14)
  [1]=>
  int(15)
  [2]=>
  int(16)
  [3]=>
  int(17)
  [4]=>
  int(18)
  [5]=>
  int(19)
  [6]=>
  int(20)
}

Which is correct (obviously the values are changed for this answer). Your result is because the combining of the $years array is appended to the default value as a whole array, rather than merging it.

richsage
Thanks richsage, and any way the indexes and the values to match?? I mean: array(8) { [""]=> string(1) "-" [14]=> int(14) [15]=>