Hi, I want to create a javascript array that duplicates the values within a PHP array.
I have looked at many resources online, but due to little understanding i havent implemented them as of yet.
What i am asked to do is duplicate this php array to a javascript array within the head of my php page. Does this mean that it needs to be a function?
Most of the code i see is relevant to sql stuff, I would be very greatfull for your help or even relevant resources
Thanks cw
Converting 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: Converting 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: Converting php array to javascript array
Json_encode()
Just read up on it, it says that it returns a string on execution.
I want to return a populated array, do you mean to say populate the javascript array with json_encode() ?
My experiance in both javascript and php are limited sorry
Just read up on it, it says that it returns a string on execution.
I want to return a populated array, do you mean to say populate the javascript array with json_encode() ?
My experiance in both javascript and php are limited sorry
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Converting php array to javascript array
Yes (example):code_worm wrote:Json_encode()
Just read up on it, it says that it returns a string on execution.
I want to return a populated array, do you mean to say populate the javascript array with json_encode() ?
My experiance in both javascript and php are limited sorry
Code: Select all
echo '<script type="text/javascript">'
'var myJSarray = ' . json_encode($myPHParray) . ';'
'</script>';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: Converting php array to javascript array
Thanks, I have never implemented this before.
Am i stupid in asking this, I am required to do this in the head section...
As this code goes in the head will it still work if the php array declaration is in the body. Does this mean i need to create a function?
Am i stupid in asking this, I am required to do this in the head section...
As this code goes in the head will it still work if the php array declaration is in the body. Does this mean i need to create a function?
Re: Converting php array to javascript array
What i am creating is a dynamic html page
If i create the javascript array within the head of my php page will i be able to acess this array through my js functions?
If i create the javascript array within the head of my php page will i be able to acess this array through my js functions?