Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Better way to do it?
  • 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.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion