php - Put specified index from an array in the top of select box


I have the following array:

   [2] => Afganistan
   [3] => Africa
   [4] => Albania
   [5] => Alegira
   [6] => Turcia

In the template .handlebars I do :

{{#each oForm.lCountry}}
    <option value="{{@key}}">

In the first value of selectbox I getAfganistan, how to do a verification tu put on the first valueTurcia ? Please help me. Thx in advance and sorry for my english




I would suggest to just mark "Turcia" as selected.

Handlebars Helper: (Javascript version)

Handlebars.registerHelper('eq', function(a, b, block) {
    return a == b ? block.fn(this) : block.inverse(this);


{{#each oForm.lCountry}}
    <option value="{{@key}}" {{#eq this 'Turcia'}}selected="true"{{/eq}}>


<option value="2" >
<option value="6" selected    Turcia

Now "Turcia", will be selected by default. Which is more logical so you can mantain the alphabetical order.

If you want "Turcia" to appear first by any means, just change the order of the array in PHP.

People are also looking for solutions to the problem: php - Send checked table row value in array


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.