Option to force keys on arrays in properties
kosciuk opened this issue · 3 comments
kosciuk commented
When I create a property and that property includes an array with the indices starting at 0 and sorted, when generating the code the keys are omitted, so if I reorder or add items the indices change.
Solution: start the array with the highest index.
Ex:
$class->addProperty('fields', $fields), with $fields['options'] = [0 => 'Unknown' ....
'options' => ['Unknown', 'New', 'Used', 'Refurbished'],
Moving 3 => "Refurbished" at the beggining, with $fields['options'] = [3 => 'Refurbished ....
'options' => [3 => 'Refurbished', 0 => 'Unknown', 1 => 'New', 2 => 'Used'],
dg commented
What do you mean by "moving"?
kosciuk commented
Reordering the array values preserving keys. Refurbished was "moved" in the example (first comment)
dg commented
Can you show me code?