Blutzeugen
Bounce Rate Slayer
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
400 XP
Creating our PHP Array
First we are going to create our PHP array.
The above code will create an array that looks like this:
Converting into Javascript Array
Finally, we convert our created PHP array into Javascript array.
In here, we will view the created javascript in the console and it will look something like this:
Full Source Code
Here's the Full Page Code.
That ends this tutorial. Happy Coding :)
Download
First we are going to create our PHP array.
- <?php
- //create example array
- $array
=
array
(
- array
(
- 'id'
=>
'1'
,
- 'firstname'
=>
'neovic'
,
- 'lastname'
=>
'devierte'
- )
,
- array
(
- 'id'
=>
'2'
,
- 'firstname'
=>
'gemalyn'
,
- 'lastname'
=>
'cepe'
- )
,
- array
(
- 'id'
=>
'1'
,
- 'firstname'
=>
'julyn'
,
- 'lastname'
=>
'divinagracia'
- )
- )
;
- ?>
The above code will create an array that looks like this:

Converting into Javascript Array
Finally, we convert our created PHP array into Javascript array.
- <
script type=
"text/javascript"
>
- //converting php array to js array
- var
array =
<?
php echo json_encode(
$array)
;
?>;
- console.log
(
array)
;
- </
script>
In here, we will view the created javascript in the console and it will look something like this:

Full Source Code
Here's the Full Page Code.
- <?php
- //create example array
- $array
=
array
(
- array
(
- 'id'
=>
'1'
,
- 'firstname'
=>
'neovic'
,
- 'lastname'
=>
'devierte'
- )
,
- array
(
- 'id'
=>
'2'
,
- 'firstname'
=>
'gemalyn'
,
- 'lastname'
=>
'cepe'
- )
,
- array
(
- 'id'
=>
'1'
,
- 'firstname'
=>
'julyn'
,
- 'lastname'
=>
'divinagracia'
- )
- )
;
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title></title>
- </head>
- <body>
- <script type="text/javascript">
- //converting php array to js array
- var array = <?php
echo
json_encode
(
$array
)
;
?>
;
- console.log(array);
- </script>
- </body>
- </html>
That ends this tutorial. Happy Coding :)
Download
You must upgrade your account or reply in the thread to view hidden text.