I'm extending the core Form_Instance and replacing the select method to add a "Select One" option to (to the beginning) dropdowns.
$noptions = array('' => 'Select');
foreach($options as $kopt=>$opt)
{
$noptions[$kopt] = $opt;
}
[/CODE]
Basically I take the incoming $options array and append the empty valued option to the beging,.
I tried array_unshift and array_merge to get the job done. While it works as expected for literal keys, it modifies the keys for numerical array keys so I ended up with the above. Is there a better way to accomplish this?[CODE]
$noptions = array('' => 'Select');
foreach($options as $kopt=>$opt)
{
$noptions[$kopt] = $opt;
}
[/CODE]
Basically I take the incoming $options array and append the empty valued option to the beging,.
I tried array_unshift and array_merge to get the job done. While it works as expected for literal keys, it modifies the keys for numerical array keys so I ended up with the above. Is there a better way to accomplish this?
Arr::insert_before_key() would take care of that.
If you don't know the first key, you can call Arr::insert() or Arr::insert_assoc(), which take a numeric position, where 0 is the first entry in the array.
Note that you have to be on 1.3 for that, I think 1.2 had similar issues with numeric keys.