Strange Return From Array

I am trying to render a form with dropdowns for width and height. The values need to be in increments of a quarter inch, i.e 1/4, 1/2, 3/4, 1, 1 1/4, etc. I am populating the dropdowns with arrays returned from the model. I get the same weird issue with both so I’ll just use the height as an example.

The view:




<?= $form->field($model, 'hs_height')->dropDownList($model->getHandStampHeights()) ?>



The model:




public function getHandStampHeights()

{

  return [

	.25 => ‘1/4’,

	.5 => ‘1/2’,

	.75 => ‘3/4’,

	1 => ‘1’,

	1.25 => ‘1 1/4’,

	1.5 => ‘1 1/2’,

	1.75 => ‘1 3/4’,

	2 => ‘2’,

	2.25 => ‘2 1/4’,

	2.5 => ‘2 1/2’,

	2.75 => ‘2 3/4’,

	3 => ‘3’,

	];

}



When I look at all the display values of the dropdown, it only shows 3/4, 1 3/4, 2 3/4, and 3. When I replace the strings with decimal values, .25 => .25, it does the same thing showing .75, 1.75, 2.75, 3. The model validation only requires number. When I remove the decimal point on the key side, 25 =>‘1/4’, it will show the 1/4. I suppose I can do this for the whole array and divide by 100 and make it work but I am just curious why the one quarter, one half and all but the last integers are skipped over.

Check the documentation for the PHP arrays… the key can be an integer or a string - http://php.net/manual/en/language.types.array.php

Thanks, that is an interesting reference. I do need the key to be numeric, and dividing the $_POST result by 100 in the controller is working. I did some experimenting just out of curiosity. [.1=>1, .2=>2, .3=>3] returned only 3. [.1=>1, .2=>2, .3=>3, .4=>4] returned only 4. It is php array handling like you say.