Arrays in Php and Javascript

Javascript coding ..

Moderators: egami, macek, gesf

Post Reply
drimades
New php-forum User
New php-forum User
Posts: 39
Joined: Wed Oct 29, 2003 2:11 pm

Wed Dec 17, 2003 9:14 am

-------------------------------------------------

How can I use an array (say $ImgArra) of Php in a function Javascript?

-------------------------------------------------

liquedus
php-forum Active User
php-forum Active User
Posts: 264
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada
Contact:

Wed Dec 17, 2003 10:10 am

you cant....

why?

Because PHP is processed on the server while JavaScript is processed client side.

User avatar
swirlee
Moderator
Moderator
Posts: 2257
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Wed Dec 17, 2003 2:16 pm

drimades wrote:How can I use an array (say $ImgArra) of Php in a function Javascript?


You're going to have to make PHP echo JavaScript code. Just use foreach() to output each element in the array as a JavaScript array element assignment.
Image

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1279
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Wed Dec 17, 2003 9:08 pm

yeh do this

Code: Select all

<script language=javascript>
<?php
foreach ($arr as $key => $value) {
   echo 'arreg[' . $key . '] = ' . $value . "\n";
}
?>
</script>

Post Reply
  • Information
  • Who is online

    Users browsing this forum: Bing [Bot] and 1 guest