Yii Framework Forum: Strange Return From Array - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Strange Return From Array

#1 User is offline   newbiedo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 72
  • Joined: 28-June 12

Posted 10 November 2017 - 12:26 PM

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.
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,542
  • Joined: 12-October 09
  • Location:Croatia

Posted 10 November 2017 - 12:59 PM

Check the documentation for the PHP arrays.. the key can be an integer or a string - http://php.net/manua...types.array.php
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   newbiedo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 72
  • Joined: 28-June 12

Posted 10 November 2017 - 01:18 PM

View PostMaurizio Domba Cerin, on 10 November 2017 - 12:59 PM, said:

Check the documentation for the PHP arrays.. the key can be an integer or a string - http://php.net/manua...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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users