Posted By

dato on 10/04/11


Tagged

javascript php array


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

boksiora
tux-world


Convert PHP array into Javascript Array


 / Published in: JavaScript
 

  1. <?php
  2. $arreglo = array(
  3. 'clave 1' => 'valor 1',
  4. 'clave 2' => 'valor 2',
  5. 'clave x' => 'valor x',
  6. );
  7. ?>
  8.  
  9. <script language="javascript">
  10. var arr = {
  11.  
  12. <?php
  13. foreach($arreglo as $key => $values){
  14. $arr .= "'" . $key . "'" . " : " . "'" . $values . "'" . ",";
  15. }
  16. $arr = substr_replace($arr, '', -1);
  17. echo $arr;
  18. ?>
  19.  
  20. };
  21. </script>

Report this snippet  

You need to login to post a comment.