Can any body tell me simple two lines code for converting PHP array to javascript array.
$arr=array("a","b","c");
I have to pass array as argument like onclick="myFunction('<? echo $arr;?>')".
<script language="javascript">
function myFunction(jsArray)
{
I want to show "a","b","c" here.
}
</script>
Can any body tell me how should i do?
PHP array to javascript Array
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: PHP array to javascript Array
json_encode()
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: PHP array to javascript Array
I didnt find any thing there to convert PHP array to javascript array there.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: PHP array to javascript Array
Well, that's exactly what it's for.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: PHP array to javascript Array
Code: Select all
<?php
$arr = array("a","b","c");
?>
<script>
var jsArray = ["<?php echo join("\", \"", $arr); ?>"];
alert(jsArray[0]);
</script>