Re: convert a php arrya to javascript array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Hi Prabakaran,

There are a couple of ways to do this, simplest is to loop through 
the PHP array, creating a string representing the creation of a 
Javascript array, then echo it to your script.  For example:

<?php

// PHP array to convert to Javascript
$vMyArray = array("a","b","c","d"); 
// The beginning definition of our javascript array (created in PHP)
$vMyJSArray = "var jsArray = new Array(";  
for ($vIdx=0; $vIdx<count($vMyArray); $vIdx++) {
   $vMyJSArray .= "\"" . $vMyArray[$vIdx] . "\"";
   if (count($vMyArray)-1 != $vIdx) {
      $vMyJSArray .= ",";
   }
}

?>
<script language="javascript">
   <?= $vMyJSArray ?>
</script>



I haven't checked that the above works, but it should give you a good 
idea.

Hope that helps,
Brian


--- In php-objects@xxxxxxxxxxxxxxx, Prabakaran Sekar 
<prabakarsekar@xxxx> wrote:
> Hi all,
> 
> I want to convert a php array to java script array any body can me?
> 
> Prabakaran





PHP Data object relational mapping generator - http://www.meta-language.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 




[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux