Ver Mensaje Individual
  #3 (permalink)  
Antiguo 06/04/2012, 10:17
Avatar de gjx2
gjx2
 
Fecha de Ingreso: agosto-2008
Ubicación: R.D
Mensajes: 1.153
Antigüedad: 15 años, 8 meses
Puntos: 139
Respuesta: Cómo pasar de php a array de javascript

Se me olvido una cuarta que es por json

Código HTML:
Ver original
  1. <?PHP
  2.         $i = 0;
  3.         $img = "";
  4.         while($i<10){
  5.            
  6.             $img[] = "valor ".$i;
  7.        
  8.         $i++;  
  9.         }
  10.    
  11.  
  12.    
  13.     ?>
  14.  
  15.  
  16. <script type="text/javascript">
  17.  
  18. var img = new Array();
  19.  
  20. window.onload = function(){
  21.  
  22.     var img  = <?=json_encode($img)?>;
  23.     alert(img[3]);
  24. }
  25.  

Última edición por gjx2; 06/04/2012 a las 10:27 Razón: había cometido un error diseñando el json