How to create javascript array in json format [closed]

0

Example of how to declare in php:

Array
(
    [0] => http://i.vimeocdn.com/video/637696211_200x150.jpg
    [1] => http://i.vimeocdn.com/video/637696227_200x150.jpg
    [2] => http://i.vimeocdn.com/video/637696217_200x150.jpg
    [3] => http://i.vimeocdn.com/video/637696211_200x150.jpg
)
    
asked by anonymous 18.08.2017 / 15:36

2 answers

2

Example to declare:

var myJson = {
'img' : [
 'http://i.vimeocdn.com/video/637696211_200x150.jpg',
 'http://i.vimeocdn.com/video/637696227_200x150.jpg',
 'http://i.vimeocdn.com/video/637696227_200x150.jpg',
 'http://i.vimeocdn.com/video/637696227_200x150.jpg'
]
}

Example to access:

myJson.img[0]

link

    
18.08.2017 / 15:41
0

You could use the json_encode function in this array

Example:

<?php
    $arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);

    echo json_encode($arr);
?>

The above example will print:

{"a":1,"b":2,"c":3,"d":4,"e":5}
    
18.08.2017 / 15:39