Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6958901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:12:02+00:00 2026-05-27T15:12:02+00:00

function loop_dropdown($valor) { for ($i = 0; $i < count($valor); $i++) { echo <option

  • 0
function loop_dropdown($valor) {
        for ($i = 0; $i < count($valor); $i++) {
            echo "<option value='$valor[$i][0]' class='dr'>".$valor[$i][1].'</option>';
        }
}

<form method="post" id="customForm2" action="">
<?php

for ($i = 0; $i < count($languages); $i++) {
    $u = $i+1;
    echo '
    <div class = "linguas" id="input_'.$u.'" style="margin-bottom: 10px;">
        <select name="myformdata[linguas][]">
        <option value="0" class="dr">Lingua</option>
        '.loop_dropdown($languages_dropdown).'
        </select> 
    </div>';
}
?>
</form>

var_dump($languages_dropdown);

  array
      0 => 
        array
          0 => int 2
          1 => string 'Espanhol' (length=8)
      1 => 
        array
          0 => int 1
          1 => string 'Português' (length=10)

Two problems:

First, i get these options. Why value="Array[0]" and not value="1" and value="2" ?

<option class="dr" value="Array[0]">Espanhol</option>
<option class="dr" value="Array[0]">Português</option>

Second problem, these two options are not appended to dropdown (select).

Any idea ?

EDIT (output html):

<form id="customForm2" action="" method="post">

<option class="dr" value="2">Espanhol</option>
<option class="dr" value="1">Português</option>

<div id="input_1" class="linguas" style="margin-bottom: 10px;">

<select name="myformdata[linguas][]">

<option class="dr" value="0">Lingua</option>

</select>
</div>

</form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:12:03+00:00Added an answer on May 27, 2026 at 3:12 pm

    Try putting $valor[$i][0] inside {}

    so :

    echo "<option value='{$valor[$i][0]}' class='dr'>".$valor[$i][1].'</option>';
    

    ** Edited code **

    function loop_dropdown($valor) {
        $output = '';
        for ($i = 0; $i < count($valor); $i++) {
            $output .= "<option value='$valor[$i][0]' class='dr'>".$valor[$i][1].'</option>';
        }
        return $output;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following function to loop through a couple of open CDB
In a multithreaded application. I have a bunch of function that loop through a
How do I run a function on a loop so all the results go
I have a thread that, when its function exits its loop (the exit is
I wrote a while loop in a function, but don't know how to stop
I wrote this function for filling closed loop, pixvali is declared globally to store
I have a function which performs a foreach loop on an array from a
I have the following loop inside an function init(); which is executed onload, I
I have a for-loop which performs the following function: Take a M by 8
I want to create a function like a for loop where I will ideally

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.