Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

92
Vistas
utilize PHP array as HTML selection

What I got.

I got an PHP which performs a user LDAP query and stores the result in an array. Within the PHP I JSON_encode($myArray) the array and pass this to an JavaScript file with print_r($myArray). In JavaScript I fill a HTML selection with the myArray as source.

The PHP results looks like, which is fine:

["Mickey Mouse","Donald Duck","Minnie Mouse"]

Whats the problem?

Usually I would fill a source based selection like this, which works with JSON files but not in this case:

var fillUserSelection

for (var key in myArray) {
   fillUserSelection += "<option>" + myArray[key] + "</option>"
}
document.getElementbyId("").innerHTML = fillUserSelection

I expected Mickey Mouse, Donald Duck and Minnie Mouse as options. Instead I receive each char as options. Like [,",M,i,c,k,e,y.. etc.

What I want.

I want only Mickey Mouse, Donald Duck and Minnie Mouse as options. What do I miss?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Try something like this.

var myArray = JSON.parse(<?php echo json_encode($phpArray) ?>);

Now your array will work.

about 4 years ago · Juan Pablo Isaza Denunciar

0

    <?php $myarray = array("Mickey Mouse","Donald Duck","Minnie Mouse"); ?>
    
    <?php json_encode($myarray); ?>
    
    
      <?php for ($i = 0; $i < count($myarray); $i++) {?>
      
      <?php echo "$myarray[$i] <br/>"; ?>
      
      <?php } ?>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda