开发者

How to convert array in PHP [duplicate]

开发者 https://www.devze.com 2023-03-24 00:37 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: PHP : Create array for JSON
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

PHP : Create array for JSON

I have an array like this :

Array ( [0] => tag1 [1] => tag2 [2] => tags17c [3] => tags20开发者_Python百科 [4] => tags21)

I want put that array on javascript, and the format must be like this :

var Tag = ['tag1', 'tag2', 'tags17c', 'tags20', 'tags21'];

How to convert it? please, help me out..


var Tag = <?php echo json_encode(array_map("htmlspecialchars", $your_array)); ?>;


My advice would be to use json for that, as Charly suggested, using json_encode. Though there is no real reason for using array_values() as far as I know,

var Tag = <?php echo json_encode($array); ?>;
0

精彩评论

暂无评论...
验证码 换一张
取 消